Return to Snippet

Revision: 17056
at August 21, 2009 14:47 by bigfaceworm


Initial Code
(defvar cycle-special-files-file-list
  '("~/.mailrc" "~/personal/.phones""~/public_html/home.html"))

(defun cycle-special-files ()
  "cycle through the set of files specified in cycle-special-files-file-list."
  (interactive)
  (let* ((cur-buffer (current-buffer))
         (buff-list (mapcar (lambda (f) (find-file-noselect (file-truename f)))  cycle-special-files-file-list))
         (2x-buff-list (append buff-list buff-list))
         (default (car buff-list))
         (res (memq cur-buffer 2x-buff-list)))

    ;; find buffer after the current one
    (if (and res (cdr res))
        (setq default (cadr res)))

    ;; bury the buffer if it's one of the special list
    (when (member cur-buffer buff-list) (bury-buffer cur-buffer))
    (when default
      (switch-to-buffer default))))

Initial URL
http://stackoverflow.com/questions/41522/tips-for-learning-elisp/59589#59589

Initial Description
An answer to the 'cycle-special-files exercise listed here: http://stackoverflow.com/questions/41522/tips-for-learning-elisp/59589#59589

Initial Title
cycle-special-files

Initial Tags
files

Initial Language
Emacs Lisp