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

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

Re: More convenient editing of recentf files


From: B. T. Raven
Subject: Re: More convenient editing of recentf files
Date: Sun, 15 Mar 2009 19:09:08 -0600
User-agent: Thunderbird 2.0.0.19 (Windows/20081209)

Drew Adams wrote:
From: B. T. Raven Sent: Sunday, March 15, 2009 11:43 AM
In .emacs I have:
(add-to-list 'same-window-buffer-names "*Buffer List*")
and '(iswitchb-mode t nil (iswitchb)) in custom-set-variables
so I can navigate to buffers quickly with C-x b and kill selected ones with C-x C-b via D, SPC, and X keys.

Is there a way to do something like this with recentf files?
Now I have to use the mousey checkbox interface:
menubar > Open Recent > Edit list > check ... check ... check .... move to bottom of list ... check ok

Perhaps someone else will give you an Iswitchb-specific answer for recentf file
deletion. If not, the following might help.

If you use Icicles, you can use `Remove from Recent Files List' in menu Files >
Icicles, or use `M-x icicle-remove-file-from-recentf-list'.

During completion, you can filter candidates with your input (e.g. substring,
regexp, prefix), and cycle among matches. Use `C-RET' or `C-mouse-2' repeatedly
to remove as many individual file names as you like.

Use `C-!' to remove all file names that match the current input pattern - use as
many patterns as you like. Use `C-~' (complement) to match against all
candidates that do *not* match some input pattern. Use `M-SPC' to combine input
patterns (logical AND): progessive completion.

(And yes, you can use Iswitchb with Icicles.)

----

Without Icicles, you could call, within a loop, a command that reads a single
absolute file name using completion (letting the user quit the loop with, e.g.,
`C-g'). A user would then complete file names to remove them from
`recentf-list'.

(defun remove-some-recent-files ()
  "Remove some files from the list of recently used files."
  (interactive)
  (while recentf-list
    (call-interactively #'remove-a-recent-file)))

Within the loop, call `completing-read' against `recentf-list'. E.g.:

(defun remove-a-recent-file (file)
  "Remove a file from the list of recently used files."
  (interactive
   (list
    (completing-read
     "Remove from recent files list (`C-g' when done): "
     (mapcar #'list
             (progn
               (unless (boundp 'recentf-list)(require 'recentf))
               (when (fboundp 'recentf-mode) (recentf-mode 99))
               (unless (consp recentf-list)
                 (error "No recently accessed files"))
               recentf-list))
     nil (and (fboundp 'confirm-nonexistent-file-or-buffer)
              (confirm-nonexistent-file-or-buffer)) ; Emacs23.
     nil 'file-name-history (car recentf-list))))
  (setq recentf-list  (delete file recentf-list))
  (message "`%s' removed from `recentf-list'" file))

If you know you're going to have `recentf.el' loaded and be in `recentf-mode',
then you can skip the first part of the `progn'. If you know you have Emacs 22+,
you can skip the `mapcar'. If you know you have Emacs 23, you can skip the
`fboundp' for `confirm-...'.

Thanks, Drew. I called the main defun prune-recentf-list and it worked but with deeply nested file hierarchy, it's still a lot of typing. For now I'll just use:

(defalias 'rel 'recentf-edit-list)
(defalias 'rof 'recentf-open-files)
(defalias 'rsl 'recentf-save-list)

so I can avoid the mouse.

Does the code below require that Icicles be installed? It looks like it depends on the existence of icicle-define-command. I probably will install icicles someday. It looks intriguing but I need to keep things as close to the standard Emacs install as possible for now.

Ed


----

FYI, a nearly identical definition suffices to define the Icicles multi-command
(no loop needed) that lets you remove as many files as you want from the list:

(icicle-define-command icicle-remove-file-from-recentf-list
  "Remove some files from the list of recently used files."
  icicle-remove-from-recentf-candidate-action
  "Remove from recent files list: "
  (mapcar #'list
          (progn
            (unless (boundp 'recentf-list) (require 'recentf))
            (when (fboundp 'recentf-mode) (recentf-mode 99))
            (unless (consp recentf-list)
              (error "No recently accessed files"))
            recentf-list))
  nil (and (fboundp 'confirm-nonexistent-file-or-buffer)
           (confirm-nonexistent-file-or-buffer))
  nil 'file-name-history (car recentf-list) nil
  ((icicle-use-candidates-only-once-flag  t)))

(defun icicle-remove-from-recentf-candidate-action (file)
  "Action function for `icicle-remove-file-from-recentf-list'."
  (setq recentf-list  (delete file recentf-list))
  (message "`%s' removed from `recentf-list'" file))

HTH.





reply via email to

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