From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thorsten Jolitz Subject: Re: a quick way to switch orgmode notes between read-only/editing? Date: Fri, 18 Jul 2014 22:37:18 +0200 Message-ID: <87zjg6mmip.fsf@gmail.com> References: <87d2d49h63.fsf@gmail.com> <8761ivsgb2.fsf@ericabrahamsen.net> <8738dzt5bp.fsf@gmail.com> <87vbqusv2q.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:57721) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X8EuW-0000LA-K2 for emacs-orgmode@gnu.org; Fri, 18 Jul 2014 16:37:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X8EuQ-0005zR-98 for emacs-orgmode@gnu.org; Fri, 18 Jul 2014 16:37:44 -0400 Received: from plane.gmane.org ([80.91.229.3]:57421) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X8EuP-0005zN-W9 for emacs-orgmode@gnu.org; Fri, 18 Jul 2014 16:37:38 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1X8EuN-0003wv-PO for emacs-orgmode@gnu.org; Fri, 18 Jul 2014 22:37:35 +0200 Received: from e178188154.adsl.alicedsl.de ([85.178.188.154]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 18 Jul 2014 22:37:35 +0200 Received: from tjolitz by e178188154.adsl.alicedsl.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 18 Jul 2014 22:37:35 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Xebar Saram writes: > Thx again Thorsten > > for some reason it wont work here. i evaluated it and have in in my > config. i open notes in view mode (the other hook i used) and then > edit them. i leave the pc for 5-10 minutes but it dosent revert to > view mode for some reason. am i missing something? it should probably be (= last-tick curr-tick) ; was (< last-tick curr-tick) but anyway, I'm not sure if this whole idea is a good one, and trying it out here had some unwanted side-effects that had me restart Emacs. maybe try it out with the = (instead of <) and set (* 5 60) to (* 1 60) so you only have to wait one minute... if it does not work then, or wrecks havoc on you system, better omit the whole thing. > On Fri, Jul 18, 2014 at 3:35 PM, Thorsten Jolitz > wrote: > > Xebar Saram writes: > > > Thx Thorsten > > > > i tried that but that dosent seem to work :) any way i can try > to > > debug this (i apologize in advance for my zero lisp knowledge :) > > > it actually worked, but only with calling the reset function > manually > once. > > try this: > > > #+begin_src emacs-lisp > (defvar tj/last-buffer-tick nil) > (make-variable-buffer-local 'tj/last-buffer-tick) > > > (defun tj/new-buffer-ticks-p () > (let ((curr-tick (buffer-modified-tick)) > (last-tick tj/last-buffer-tick)) > (setq tj/last-buffer-tick curr-tick) > > (and last-tick (< last-tick curr-tick)))) > > (defun tj/reset-view-mode () > (run-with-timer 0 (* 5 60) > > (lambda () > (when (tj/new-buffer-ticks-p) > (view-mode t))))) > > > (add-hook 'org-mode-hook 'tj/reset-view-mode) > > > #+end_src > > > On Fri, Jul 18, 2014 at 11:54 AM, Thorsten Jolitz > > > wrote: > > > > Xebar Saram writes: > > > > > Thx again all, really cool. > > > > > > one last question. anyone mind pasting code to revert an open > > buffer > > > to read only when idle for lets say 5 minutes? > > > > > > you could try this (untested!): > > > > #+begin_src emacs-lisp > > (defvar tj/last-buffer-tick nil) > > (make-variable-buffer-local 'tj/last-buffer-tick) > > > > (add-hook 'org-mode-hook > > (lambda () > > (setq tj/last-buffer-tick (buffer-modified-tick)))) > > > > (defun tj/new-buffer-ticks-p () > > (let ((curr-tick (buffer-modified-tick)) > > (last-tick tj/last-buffer-tick)) > > (setq tj/last-buffer-tick curr-tick) > > (< last-tick curr-tick))) > > > > (defun tj/reset-view-mode () > > (run-with-timer (* 5 60) (* 5 60) > > (lambda () > > (when (tj/new-buffer-ticks-p) > > (view-mode t))))) > > #+end_src > > > > > > > > > > > On Fri, Jul 18, 2014 at 2:42 AM, Eric Abrahamsen > > > wrote: > > > > > > Xebar Saram writes: > > > > > > > Thanks guys. really appreciate all your help > > > > > > > > im now using view-mode with hooks as suggested. btw whats > the > > > > advantages of viewer-mode over read-only-mode > > > > > > > > > Mostly that you get more convenient navigation commands. > > Scrolling > > > and > > > searching etc don't require control modifiers, and it becomes > a > > > bit > > > easier to move around files. > > > > > > > > > > > > > best > > > > > > > > Z > > > > > > > > > > > > On Thu, Jul 17, 2014 at 5:46 PM, Jorge A. Alfaro-Murillo < > > > > jorge.a.alfaro@gmail.com> wrote: > > > > > > > > Xebar Saram writes: > > > > > > > > > i keep once and a while screwing up my notes with > unintended > > > > editing > > > > > (erroneous key presses etc) and was wondering if any one > > knew > > > > of a way > > > > > to to switch orgmode notes between read-only/editing? > > > > > > > > Hi Xebar. Use C-x C-q. This works for every file, I use it > in > > > > particular > > > > for notes that I do not want to edit. > > > > > > > > It runs the command read-only-mode which changes whether the > > > > current > > > > buffer is read-only. Actually the command switches the local > > > > variable > > > > buffer-read-only, so you can use that variable as local for > > > every > > > > file > > > > that you do not want to edit by default. At the end of those > > > > files add: > > > > > > > > #+BEGIN_EXAMPLE > > > > %%% Local Variables: > > > > %%% buffer-read-only: t > > > > %%% End: > > > > #+END_EXAMPLE > > > > > > > > And every time that you want to edit them just do C-x C-q > > > > > > > > Best, > > > > > > > > Jorge. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > cheers, > > Thorsten > > > > > > > > > > > -- > cheers, > Thorsten > > > > -- cheers, Thorsten