tl;dr Which keymap is active in helm-recentf? Or is there a better way to accomplish my goal?

I want to use emacs as my file browser. When I select a file with helm-find-files or helm-recentf, I want to check whether the extension is in a whitelist (eg. "pdf", "png", "docx") and if it is, open the file in the appropriate external program. If it's not, the file should be visited normally in emacs.

Solutions I've rejected:

  1. Use C-c C-x in helm to open candidate externally. I don't want to press a separate keybinding or to be prompted for a program name, I just want to press return as usual and have helm figure out the right thing to do.

  2. Use the openwith package. It breaks things like mu4e attachments and images embedded in org buffers. I only ever want files I explicitly open through helm to be opened externally.

What I've tried so far:

I remapped RET to a custom function that does what I want. It's probably a horrible hack, but it works for helm-find-files!

(define-key helm-find-files-map (kbd "RET") 'my-helm-ff-run-open-in-emacs-or-externally)

(defun my-helm-ff-run-open-in-emacs-or-externally ()                                
    (helm-exit-and-execute-action 'my-helm-ff-open-in-emacs-or-externally)          

(defun my-helm-ff-open-in-emacs-or-externally (file)                                
  ;; based on helm-open-file-externally,                                            
  ;; Copyright (C) 2012 ~ 2016 Thierry Volpiatto <[email protected]>      
  "Open FILE either with emacs or with an external program.                         
Try to guess which external program to use with `helm-get-default-program-for-file'.
If not found, open file in emacs."                                                  
  (if (bufferp file)                                                                
      (switch-to-buffer file)                                                       
    (let* ((file-name      (expand-file-name file))                                 
           (collection      (helm-external-commands-list-1 'sort))                  
           (default-program   (helm-get-default-program-for-file file-name)))       
      (if (not default-program)                                                     
          (find-file file) ;; open in emacs                                         
        (helm-run-or-raise default-program file) ;; open in external program        

The only problem is, I can't define this mapping for helm-recentf. I assumed that the helm-buffer-map would be active in helm-recentf, but it's not:

(define-key helm-buffer-map (kbd "RET") '(lambda () (interactive) (message "define-key worked!")))

The message prints when I select a buffer in helm-mini, but not when I select a file in helm-recentf.


So, which keymap is active in helm-recentf?

Or, am I doing this all wrong, and is there a much better to intelligently open some files with an external program?

  • Helm should prompt you once for an external program to open a file of a certain type, then use that program thereafter. Is it prompting you every time, even after you've specified the external program once already for, say, a PDF? Oct 12, 2016 at 5:01
  • Also, helm-find-files-map is the map that's active when using helm-find-files and helm-recentf. Oct 12, 2016 at 5:05
  • It doesn't prompt me more than once, but it doesn't allow me to open a file in emacs. So I'd still need to use 2 separate commands for external vs internal.
    – e-matteson
    Oct 12, 2016 at 5:47
  • Are you sure about helm-find-files-map? When I bind something to RET in helm-find-files-map, like the message example above, it works in helm-find-files but not in helm-recentf.
    – e-matteson
    Oct 12, 2016 at 5:50

1 Answer 1


Which keymap is active in helm-recentf?

It's helm-generic-files-map, inherits from the helm-type-file class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.