* Diego Zamboni <di...@zzamboni.org> [2020-11-23 12:53]: > Hi Gerardo, > > Apart from what others have suggested, what you can do if you have a fixed > list of files you want to quickly access, you could manually define > keybindings for them. I have four main files where I capture things, so I > define a submenu that allows me to access them quickly: > > (note: I got this idea originally from Sacha Chua's > https://sachachua.com/blog/2015/02/learn-take-notes-efficiently-org-mode/) > > First, I define a helper function to define keybindings that open files. > Note that this requires lexical binding to be enabled, so that the > =lambda= creates a closure, otherwise the keybindings don't work. > > #+begin_src emacs-lisp > (defun zz/add-file-keybinding (key file &optional desc) > (let ((key key) > (file file) > (desc desc)) > (map! :desc (or desc file) > key > (lambda () (interactive) (find-file file))))) > #+end_src > > (note #2: the map! macro is Doom Emacs-specific, should be replaced with > `bind-key` or equivalent if you are not using Doom) > > Now I define keybindings to access my commonly-used org files. > > #+begin_src emacs-lisp > (zz/add-file-keybinding "C-c z w" "~/Work/work.org.gpg" "work.org") > (zz/add-file-keybinding "C-c z i" "~/org/ideas.org" "ideas.org") > (zz/add-file-keybinding "C-c z p" "~/org/projects.org" "projects.org") > (zz/add-file-keybinding "C-c z d" "~/org/diary.org" "diary.org") > #+end_src
Another idea how to quickly access those files could be with completion function which could also be bound to a key. (defun my-org-files () (interactive) (let* ((list '(("Work" . "~/Work/work.org.gpg") ("Ideas" . "~/org/ideas.org") ("Projects" . "~/org/projects.org") ("Diary" . "~/org/diary.org"))) (completion-ignore-case t) (file (completing-read "My files: " list)) (file (cdr (assoc file list)))) (find-file file))) or function that finds all org files and offers completion on such: (defun my-all-org-files () (interactive) (let* ((my-org-dir "~/Documents/Org") (all-org (directory-files my-org-dir t "\.org$")) (alist '()) (all-org-alist (dolist (org all-org alist) (setf (alist-get (file-name-base org) alist) org))) (completion-ignore-case t) (file (completing-read "My files: " all-org-alist)) (file (cdr (assoc file alist)))) (find-file file))) M-x my-all-org-files Even better is when you turn on some visual completion package such as M-x ivy-mode or M-x helm-mode package ivy is in GNU ELPA