Posted By

bigfaceworm on 08/21/09


Tagged

files emacs LISP cycle


Versions (?)

cycle-special-files


 / Published in: Emacs Lisp
 

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

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

  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))))

Report this snippet  

You need to login to post a comment.