[Emacs] Move out function definition for `phundrak/find-org-files'

This commit promotes a lambda to an actual function and moves it to the
custom functions part.
This commit is contained in:
Lucien Cartier-Tilet 2020-10-09 18:08:58 +02:00
parent ae0b14d962
commit fb0263a3b7
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA

View File

@ -1423,6 +1423,42 @@
'("st"))
#+END_SRC
*** ~phundrak/find-org-file~
:PROPERTIES:
:CUSTOM_ID: User_Configuration-Custom_functions-phundrakfind-org-file-029040a5
:END:
There are lots of files which I want to be able to quickly open. I used to
have one shortcut for each one of these files, but as their number grew, I
decided to switch to helm for my file selector which will be called by only
one common shortcut. Most of my files will be located in =~/org=, but I have
some conlanging files which are located in =~/Documents/conlanging=, and all
my university notes are in =~/Documents/university=. Lets declare these
directories in a variable:
#+BEGIN_SRC emacs-lisp
(setq phundrak/org-directories '("~/org"
"~/Documents/university"
"~/Documents/conlanging"))
#+END_SRC
With this established, lets write some emacs-lisp that will allow me to get
a list of all these files and select them through helm. Be aware that I will
be using some functions from third party packages, such as [[https://github.com/rejeep/f.el][f.el]] and [[https://github.com/magnars/dash.el][dash]].
#+BEGIN_SRC emacs-lisp
(defun phundrak/find-org-file ()
(interactive)
(find-file
(helm
:sources (helm-build-sync-source "org files"
:candidates (-mapcat
(lambda (path)
(f-files path
(lambda (file) (equal (f-ext file) "org"))
t))
phundrak/org-directories)
:fuzzy-match t)
:buffer "*org files*")))
#+END_SRC
** Emacs builtins
:PROPERTIES:
:CUSTOM_ID: User_Configuration-Emacs_builtins-7822b8dd
@ -2950,39 +2986,9 @@
:PROPERTIES:
:CUSTOM_ID: User_Configuration-Shortcuts-Files-206c2126
:END:
There are lots of files which I want to be able to quickly open. I used to
have one shortcut for each one of these files, but as their number grew, I
decided to switch to helm for my file selector which will be called by only
one common shortcut. Most of my files will be located in =~/org=, but I have
some conlanging files which are located in =~/Documents/conlanging=, and all
my university notes are in =~/Documents/university=. Lets declare these
directories in a variable:
#+BEGIN_SRC emacs-lisp
(setq phundrak/org-directories '("~/org"
"~/Documents/university"
"~/Documents/conlanging"))
#+END_SRC
With this established, lets write some emacs-lisp that will allow me to get
a list of all these files and select them through helm. Be aware that I will
be using some functions from third party packages, such as [[https://github.com/rejeep/f.el][f.el]] and [[https://github.com/magnars/dash.el][dash]].
#+BEGIN_SRC emacs-lisp
(spacemacs/declare-prefix "of" "open org file")
(spacemacs/set-leader-keys
"of"
(lambda ()
(interactive)
(find-file
(helm
:sources (helm-build-sync-source "org files"
:candidates (-mapcat
(lambda (path)
(f-files path
(lambda (file) (equal (f-ext file) "org"))
t))
phundrak/org-directories)
:fuzzy-match t)
:buffer "*org files*"))))
(spacemacs/set-leader-keys "of" 'phundrak/find-org-file)
#+END_SRC
I also have a shortcut for ~helm-locate~ in case I need to find a file that