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

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

recentf function to manually add files to recentf-save-file


From: John Magolske
Subject: recentf function to manually add files to recentf-save-file
Date: Tue, 18 Apr 2017 14:35:12 -0700
User-agent: Mutt/1.5.23 (2014-03-12)

The behaviour I'd like for adding files to recentf is to have a
function bound to a key that places the current file in the buffer
into the recentf-save-file. This way recentf would keep track of
only the files that I explicitly tell it to, one keypress at a time.
In this scenario, the *only* time any file would be added to the
recentf-save-file would be when this function is run. I'd rather not
bother with running something every so often that places files that
happen to be open at that time into the recentf-save-file, figuring
out what files to exclude, synchronizing between different instances
of Emacs, etc.

Below is what I've come up with so far. The current file in buffer
is placed into the recentf-save-file whenever I press my "save" key.
Not sure if there's a better way to go about this or if I overlooked
something...any suggestions/perspectives are welcome.


;;;; elisp ;;;;

(require 'recentf)
(require 'sync-recentf)
(setq recentf-save-file (expand-file-name "recentf" user-emacs-directory)
      recentf-max-saved-items 1000)
(recentf-mode 1)

(defun jfm-add-buffer-file-to-recentf ()
  "add file in buffer to the recent list, cleanup the list (remove
duplicates, excluded files, etc.) and save to recentf-save-file"
  (interactive)
  (when (buffer-file-name)
    (recentf-add-file (buffer-file-name))
    (recentf-cleanup)
    (recentf-save-list))
  nil)

(global-set-key (kbd "<f8>")
                (lambda ()
                  (interactive)
                  (jfm-add-buffer-file-to-recentf) (save-buffer)))

(defalias 'rel 'recentf-edit-list)

;;;; end elisp ;;;;


Regards,

John

-- 
John Magolske
http://b79.net/contact



reply via email to

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