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-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:
C-c C-xin 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
returnas usual and have helm figure out the right thing to do.
openwithpackage. 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:
RET to a custom function that does what I want. It's probably a horrible hack, but it works for
(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 () (interactive) (with-helm-alive-p (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 <firstname.lastname@example.org> "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
So, which keymap is active in
Or, am I doing this all wrong, and is there a much better to intelligently open some files with an external program?