From mboxrd@z Thu Jan 1 00:00:00 1970 From: Xebar Saram Subject: Re: a quick way to switch orgmode notes between read-only/editing? Date: Fri, 18 Jul 2014 18:31:32 +0300 Message-ID: References: <87d2d49h63.fsf@gmail.com> <8761ivsgb2.fsf@ericabrahamsen.net> <8738dzt5bp.fsf@gmail.com> <87vbqusv2q.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=089e01538deebbd6ca04fe7973ee Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:56281) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X8A8H-0007rY-NW for emacs-orgmode@gnu.org; Fri, 18 Jul 2014 11:31:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X8A8F-0000lP-Rk for emacs-orgmode@gnu.org; Fri, 18 Jul 2014 11:31:37 -0400 Received: from mail-oa0-x236.google.com ([2607:f8b0:4003:c02::236]:43290) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X8A8F-0000lD-KR for emacs-orgmode@gnu.org; Fri, 18 Jul 2014 11:31:35 -0400 Received: by mail-oa0-f54.google.com with SMTP id n16so3414600oag.41 for ; Fri, 18 Jul 2014 08:31:33 -0700 (PDT) In-Reply-To: <87vbqusv2q.fsf@gmail.com> 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: Thorsten Jolitz Cc: org mode --089e01538deebbd6ca04fe7973ee Content-Type: text/plain; charset=UTF-8 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? thx! Z 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 > > > --089e01538deebbd6ca04fe7973ee Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Thx again Thorsten

for some reason it w= ont work here. i evaluated it and have in in my config. i open notes in vie= w 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 som= ething?

thx!

Z


On Fri, Jul 18, 2014 at= 3:35 PM, Thorsten Jolitz <tjolitz@gmail.com> wrote:
Xebar Saram <zeltakc@gmail.com> 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 ()
=C2=A0 (let ((curr-tick (buffer-modified-tick))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (last-tick tj/last-buffer-tick))
=C2=A0 =C2=A0 (setq tj/last-buffer-tick curr-tick)
=C2=A0 =C2=A0 (and last-tick (< last-tick curr-tick))))

(defun tj/reset-view-mode ()
=C2=A0 (run-with-timer 0 (* 5 60)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 (lambda ()
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (when= (tj/new-buffer-ticks-p)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 (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 <tjolitz@gmail.com>
> wrote:
>
> =C2=A0 =C2=A0 Xebar Saram <zel= takc@gmail.com> writes:
>
> =C2=A0 =C2=A0 > Thx again all, really cool.
> =C2=A0 =C2=A0 >
> =C2=A0 =C2=A0 > one last question. anyone mind pasting code to reve= rt an open
> =C2=A0 =C2=A0 buffer
> =C2=A0 =C2=A0 > to read only when idle for lets say 5 minutes?
>
>
> =C2=A0 =C2=A0 you could try this (untested!):
>
> =C2=A0 =C2=A0 #+begin_src emacs-lisp
> =C2=A0 =C2=A0 (defvar tj/last-buffer-tick nil)
> =C2=A0 =C2=A0 (make-variable-buffer-local 'tj/last-buffer-tick) >
> =C2=A0 =C2=A0 (add-hook 'org-mode-hook
> =C2=A0 =C2=A0 (lambda ()
> =C2=A0 =C2=A0 (setq tj/last-buffer-tick (buffer-modified-tick))))
>
> =C2=A0 =C2=A0 (defun tj/new-buffer-ticks-p ()
> =C2=A0 =C2=A0 (let ((curr-tick (buffer-modified-tick))
> =C2=A0 =C2=A0 (last-tick tj/last-buffer-tick))
> =C2=A0 =C2=A0 (setq tj/last-buffer-tick curr-tick)
> =C2=A0 =C2=A0 (< last-tick curr-tick)))
>
> =C2=A0 =C2=A0 (defun tj/reset-view-mode ()
> =C2=A0 =C2=A0 (run-with-timer (* 5 60) (* 5 60)
> =C2=A0 =C2=A0 (lambda ()
> =C2=A0 =C2=A0 (when (tj/new-buffer-ticks-p)
> =C2=A0 =C2=A0 (view-mode t)))))
> =C2=A0 =C2=A0 #+end_src
>
>
>
>
> =C2=A0 =C2=A0 > On Fri, Jul 18, 2014 at 2:42 AM, Eric Abrahamsen > =C2=A0 =C2=A0 > <eric= @ericabrahamsen.net> wrote:
> =C2=A0 =C2=A0 >
> =C2=A0 =C2=A0 > Xebar Saram <zeltakc@gmail.com> writes:
> =C2=A0 =C2=A0 >
> =C2=A0 =C2=A0 > > Thanks guys. really appreciate all your help > =C2=A0 =C2=A0 > >
> =C2=A0 =C2=A0 > > im now using view-mode with hooks as suggested= . btw whats the
> =C2=A0 =C2=A0 > > advantages of viewer-mode over read-only-mode<= br> > =C2=A0 =C2=A0 >
> =C2=A0 =C2=A0 >
> =C2=A0 =C2=A0 > Mostly that you get more convenient navigation comm= ands.
> =C2=A0 =C2=A0 Scrolling
> =C2=A0 =C2=A0 > and
> =C2=A0 =C2=A0 > searching etc don't require control modifiers, = and it becomes a
> =C2=A0 =C2=A0 > bit
> =C2=A0 =C2=A0 > easier to move around files.
> =C2=A0 =C2=A0 >
> =C2=A0 =C2=A0 >
> =C2=A0 =C2=A0 >
> =C2=A0 =C2=A0 > > best
> =C2=A0 =C2=A0 > >
> =C2=A0 =C2=A0 > > Z
> =C2=A0 =C2=A0 > >
> =C2=A0 =C2=A0 > >
> =C2=A0 =C2=A0 > > On Thu, Jul 17, 2014 at 5:46 PM, Jorge A. Alfa= ro-Murillo <
> =C2=A0 =C2=A0 > > jo= rge.a.alfaro@gmail.com> wrote:
> =C2=A0 =C2=A0 > >
> =C2=A0 =C2=A0 > > Xebar Saram <zeltakc@gmail.com> writes:
> =C2=A0 =C2=A0 > >
> =C2=A0 =C2=A0 > > > i keep once and a while screwing up my no= tes with unintended
> =C2=A0 =C2=A0 > > editing
> =C2=A0 =C2=A0 > > > (erroneous key presses etc) and was wonde= ring if any one
> =C2=A0 =C2=A0 knew
> =C2=A0 =C2=A0 > > of a way
> =C2=A0 =C2=A0 > > > to to switch orgmode notes between read-o= nly/editing?
> =C2=A0 =C2=A0 > >
> =C2=A0 =C2=A0 > > Hi Xebar. Use C-x C-q. This works for every fi= le, I use it in
> =C2=A0 =C2=A0 > > particular
> =C2=A0 =C2=A0 > > for notes that I do not want to edit.
> =C2=A0 =C2=A0 > >
> =C2=A0 =C2=A0 > > It runs the command read-only-mode which chang= es whether the
> =C2=A0 =C2=A0 > > current
> =C2=A0 =C2=A0 > > buffer is read-only. Actually the command swit= ches the local
> =C2=A0 =C2=A0 > > variable
> =C2=A0 =C2=A0 > > buffer-read-only, so you can use that variable= as local for
> =C2=A0 =C2=A0 > every
> =C2=A0 =C2=A0 > > file
> =C2=A0 =C2=A0 > > that you do not want to edit by default. At th= e end of those
> =C2=A0 =C2=A0 > > files add:
> =C2=A0 =C2=A0 > >
> =C2=A0 =C2=A0 > > #+BEGIN_EXAMPLE
> =C2=A0 =C2=A0 > > %%% Local Variables:
> =C2=A0 =C2=A0 > > %%% buffer-read-only: t
> =C2=A0 =C2=A0 > > %%% End:
> =C2=A0 =C2=A0 > > #+END_EXAMPLE
> =C2=A0 =C2=A0 > >
> =C2=A0 =C2=A0 > > And every time that you want to edit them just= do C-x C-q
> =C2=A0 =C2=A0 > >
> =C2=A0 =C2=A0 > > Best,
> =C2=A0 =C2=A0 > >
> =C2=A0 =C2=A0 > > Jorge.
> =C2=A0 =C2=A0 > >
> =C2=A0 =C2=A0 > >
> =C2=A0 =C2=A0 >
> =C2=A0 =C2=A0 >
> =C2=A0 =C2=A0 >
> =C2=A0 =C2=A0 >
> =C2=A0 =C2=A0 >
>
>
> =C2=A0 =C2=A0 --
> =C2=A0 =C2=A0 cheers,
> =C2=A0 =C2=A0 Thorsten
>
>
>
>

--
cheers,
Thorsten



--089e01538deebbd6ca04fe7973ee--