help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Cycle Org Shift Select


From: Drew Adams
Subject: RE: Cycle Org Shift Select
Date: Wed, 11 Nov 2020 09:09:25 -0800 (PST)

> > (defun Org-Shftsel-Cycle ()
> >   (interactive)
> >   (setq org-support-shift-select
> >         (cadr (memq org-support-shift-select '(nil t always nil)))))
> 
> Elegant Lisp, IMO!  A good idiom.
> ___
> 
> 
> Slightly cuter: the last nil isn't needed, since (car nil) = nil.
> 
> (defvar toto nil)
> 
> (defun foo ()
>   (interactive)
>   (setq toto  (cadr (memq toto '(nil t always))))
>   (message "NOW: %s" toto))
> 
> Of if you want to show also what'll come next:
> 
> (defun foo ()
>   (interactive)
>   (let ((xs  '(nil t always))
>         next)
>     (setq toto  (cadr (memq toto xs))
>           next  (cadr (memq toto xs)))
>     (message "NOW: %s, NEXT: %s" toto next)))

On the other hand, if you want to be able to go either
forward or backward then you might want to use a ring
(as defined in standard library ring.el):

(defvar ring (ring-convert-sequence-to-ring '(nil t always)))
(defvar current nil)

(defun next ()
  (interactive)
  (setq current  (ring-next toto current))
  (message "NOW: %s" current))

(defun previous ()
  (interactive)
  (setq current  (ring-previous toto current))
  (message "NOW: %s" current))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]