cycle-special-files


/ Published in: Emacs Lisp
Save to your folder(s)

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


Copy this code and paste it in your HTML
  1. (defvar cycle-special-files-file-list
  2. '("~/.mailrc" "~/personal/.phones""~/public_html/home.html"))
  3.  
  4. (defun cycle-special-files ()
  5. "cycle through the set of files specified in cycle-special-files-file-list."
  6. (interactive)
  7. (let* ((cur-buffer (current-buffer))
  8. (buff-list (mapcar (lambda (f) (find-file-noselect (file-truename f))) cycle-special-files-file-list))
  9. (2x-buff-list (append buff-list buff-list))
  10. (default (car buff-list))
  11. (res (memq cur-buffer 2x-buff-list)))
  12.  
  13. ;; find buffer after the current one
  14. (if (and res (cdr res))
  15. (setq default (cadr res)))
  16.  
  17. ;; bury the buffer if it's one of the special list
  18. (when (member cur-buffer buff-list) (bury-buffer cur-buffer))
  19. (when default
  20. (switch-to-buffer default))))

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.