From f0f07a6cc0057e7d996a7d1dde74ea392abb22e9 Mon Sep 17 00:00:00 2001 From: Lucien Cartier-Tilet Date: Sun, 13 Sep 2020 18:02:56 +0200 Subject: [PATCH] [Emacs] Unified my shortcuts for opening files Since all my files that were opened with a `SPC o f' prefixed shortcut all opened some org file located in precise directories, I unified them all with a helm menu and only a couple of directories to specify (I even added some). --- .spacemacs | 2 +- org/config/spacemacs.org | 112 +++++++++++++-------------------------- 2 files changed, 37 insertions(+), 77 deletions(-) diff --git a/.spacemacs b/.spacemacs index 00dd7de..1b97a79 100644 --- a/.spacemacs +++ b/.spacemacs @@ -121,7 +121,7 @@ This function is called at the very end of Spacemacs initialization." '(objed-cursor-color "#ff6c6b") '(org-export-headline-levels 4) '(package-selected-packages - '(curl-to-elisp org-tree-slide wrap-region helm-icons org-treeusage caddyfile-mode org-ref lsp-dart mu4e-maildirs-extension mu4e-alert helm-mu xkcd vmd-mode visual-fill-column typit mmt sudoku restclient-helm pony-mode pacmacs ox-reveal outorg ob-restclient ob-http meson-mode ibuffer-projectile lv helm-w3m w3m graphviz-dot-mode flycheck-gometalinter transient ess-smart-equals ess-R-data-view ctable ess julia-mode eshell-git-prompt emoji-cheat-sheet-plus edit-indirect dockerfile-mode docker docker-tramp company-restclient restclient know-your-http-well company-quickhelp company-emoji company-emacs-eclim eclim atomic-chrome websocket 2048-game ox-gfm slime-company slime common-lisp-snippets erlang insert-shebang fish-mode company-shell faceup racket-mode treepy graphql yapfify yaml-mode xterm-color web-beautify twittering-mode toml-mode tagedit stickyfunc-enhance smeargle slim-mode shell-pop selectric-mode scss-mode sass-mode ranger rainbow-identifiers pytest pyenv-mode py-isort pug-mode plantuml-mode phpunit phpcbf php-auto-yasnippets pdf-tools tablist ox-pandoc orgit org-present org-pomodoro alert log4e gntp ob-elixir multi-term markdown-toc magit-gitflow magit-gh-pulls livid-mode live-py-mode json-snatcher js2-refactor js-doc htmlize hlint-refactor hindent helm-pydoc helm-hoogle helm-gitignore helm-css-scss haskell-snippets haml-mode gnuplot glsl-mode gitignore-mode github-search github-clone github-browse-file gitconfig-mode gitattributes-mode git-messenger gist gh marshal logito pcache ht gh-md flyspell-correct-helm flyspell-correct flycheck-rust pos-tip flycheck-mix flycheck-credo eshell-z eshell-prompt-extras esh-help drupal-mode disaster cython-mode dash-functional tern company-ghci company-ghc ghc color-identifiers-mode cmm-mode clang-format cargo auto-dictionary alchemist modern-cpp-font-lock yasnippet-snippets x86-lookup web-mode srefactor racer pyvenv pip-requirements pandoc-mode org-projectile org-category-capture org-mime org-download nasm-mode json-reformat intero imenu-list hy-mode git-timemachine git-link geiser flycheck-pos-tip flycheck-haskell evil-magit emmet-mode cmake-mode anaconda-mode rust-mode elixir-mode flycheck haskell-mode multiple-cursors skewer-mode simple-httpd markdown-mode magit magit-popup git-commit ghub with-editor pythonic emms gmail-message-mode ham-mode html-to-markdown flymd edit-server image-dired+ go-guru go-eldoc company-go go-mode unfill mwim company-web web-completion-data company-tern company-cabal company-c-headers company-auctex company-anaconda elcord xresources-theme sql-indent rainbow-mode php-extras php-mode mmm-mode json-mode js2-mode csv-mode coffee-mode auctex helm-company helm-c-yasnippet fuzzy company-statistics company auto-yasnippet yasnippet ac-ispell auto-complete ws-butler winum which-key volatile-highlights vi-tilde-fringe uuidgen use-package toc-org spaceline powerline restart-emacs request rainbow-delimiters popwin persp-mode pcre2el paradox spinner org-plus-contrib org-bullets open-junk-file neotree move-text macrostep lorem-ipsum linum-relative link-hint indent-guide hydra hungry-delete hl-todo highlight-parentheses highlight-numbers parent-mode highlight-indentation helm-themes helm-swoop helm-projectile helm-mode-manager helm-make projectile pkg-info epl helm-flx helm-descbinds helm-ag google-translate golden-ratio flx-ido flx fill-column-indicator fancy-battery eyebrowse expand-region exec-path-from-shell evil-visualstar evil-visual-mark-mode evil-unimpaired evil-tutor evil-surround evil-search-highlight-persist evil-numbers evil-nerd-commenter evil-mc evil-matchit evil-lisp-state smartparens evil-indent-plus evil-iedit-state iedit evil-exchange evil-escape evil-ediff evil-args evil-anzu anzu evil goto-chg undo-tree eval-sexp-fu highlight elisp-slime-nav dumb-jump f dash s diminish define-word column-enforce-mode clean-aindent-mode bind-map bind-key auto-highlight-symbol auto-compile packed aggressive-indent adaptive-wrap ace-window ace-link ace-jump-helm-line helm avy helm-core popup async)) + '(wttrin wrap-region pinentry org-tree-slide org-sidebar org-ql peg ov org-super-agenda ts dired-du caddyfile-mode loop xkcd vmd-mode visual-fill-column typit mmt sudoku restclient-helm pony-mode pacmacs ox-reveal outorg ob-restclient ob-http meson-mode ibuffer-projectile lv helm-w3m w3m graphviz-dot-mode flycheck-gometalinter transient ess-smart-equals ess-R-data-view ctable ess julia-mode eshell-git-prompt emoji-cheat-sheet-plus edit-indirect dockerfile-mode docker docker-tramp company-restclient restclient know-your-http-well company-quickhelp company-emoji company-emacs-eclim eclim atomic-chrome websocket 2048-game ox-gfm slime-company slime common-lisp-snippets erlang insert-shebang fish-mode company-shell faceup racket-mode treepy graphql yapfify yaml-mode xterm-color web-beautify twittering-mode toml-mode tagedit stickyfunc-enhance smeargle slim-mode shell-pop selectric-mode scss-mode sass-mode ranger rainbow-identifiers pytest pyenv-mode py-isort pug-mode plantuml-mode phpunit phpcbf php-auto-yasnippets pdf-tools tablist ox-pandoc orgit org-present org-pomodoro alert log4e gntp ob-elixir multi-term markdown-toc magit-gitflow magit-gh-pulls livid-mode live-py-mode json-snatcher js2-refactor js-doc htmlize hlint-refactor hindent helm-pydoc helm-hoogle helm-gitignore helm-css-scss haskell-snippets haml-mode gnuplot glsl-mode gitignore-mode github-search github-clone github-browse-file gitconfig-mode gitattributes-mode git-messenger gist gh marshal logito pcache ht gh-md flyspell-correct-helm flyspell-correct flycheck-rust pos-tip flycheck-mix flycheck-credo eshell-z eshell-prompt-extras esh-help drupal-mode disaster cython-mode dash-functional tern company-ghci company-ghc ghc color-identifiers-mode cmm-mode clang-format cargo auto-dictionary alchemist modern-cpp-font-lock yasnippet-snippets x86-lookup web-mode srefactor racer pyvenv pip-requirements pandoc-mode org-projectile org-category-capture org-mime org-download nasm-mode json-reformat intero imenu-list hy-mode git-timemachine git-link geiser flycheck-pos-tip flycheck-haskell evil-magit emmet-mode cmake-mode anaconda-mode rust-mode elixir-mode flycheck haskell-mode multiple-cursors skewer-mode simple-httpd markdown-mode magit magit-popup git-commit ghub with-editor pythonic emms gmail-message-mode ham-mode html-to-markdown flymd edit-server image-dired+ go-guru go-eldoc company-go go-mode unfill mwim company-web web-completion-data company-tern company-cabal company-c-headers company-auctex company-anaconda elcord xresources-theme sql-indent rainbow-mode php-extras php-mode mmm-mode json-mode js2-mode csv-mode coffee-mode auctex helm-company helm-c-yasnippet fuzzy company-statistics company auto-yasnippet yasnippet ac-ispell auto-complete ws-butler winum which-key volatile-highlights vi-tilde-fringe uuidgen use-package toc-org spaceline powerline restart-emacs request rainbow-delimiters popwin persp-mode pcre2el paradox spinner org-plus-contrib org-bullets open-junk-file neotree move-text macrostep lorem-ipsum linum-relative link-hint indent-guide hydra hungry-delete hl-todo highlight-parentheses highlight-numbers parent-mode highlight-indentation helm-themes helm-swoop helm-projectile helm-mode-manager helm-make projectile pkg-info epl helm-flx helm-descbinds helm-ag google-translate golden-ratio flx-ido flx fill-column-indicator fancy-battery eyebrowse expand-region exec-path-from-shell evil-visualstar evil-visual-mark-mode evil-unimpaired evil-tutor evil-surround evil-search-highlight-persist evil-numbers evil-nerd-commenter evil-mc evil-matchit evil-lisp-state smartparens evil-indent-plus evil-iedit-state iedit evil-exchange evil-escape evil-ediff evil-args evil-anzu anzu evil goto-chg undo-tree eval-sexp-fu highlight elisp-slime-nav dumb-jump f dash s diminish define-word column-enforce-mode clean-aindent-mode bind-map bind-key auto-highlight-symbol auto-compile packed aggressive-indent adaptive-wrap ace-window ace-link ace-jump-helm-line helm avy helm-core popup async)) '(pdf-view-midnight-colors '("#655370" . "#fbf8ef")) '(safe-local-variable-values '((org-confirm-babel-evaluate) diff --git a/org/config/spacemacs.org b/org/config/spacemacs.org index cf51d93..2ee0a5c 100644 --- a/org/config/spacemacs.org +++ b/org/config/spacemacs.org @@ -123,7 +123,7 @@ It is possible to also list packages that cannot be updated: #+BEGIN_SRC emacs-lisp - (setq-default dotspacemacs-frozen-packages '()) + (setq-default dotspacemacs-frozen-packages '(helm-icons)) #+END_SRC And to list packages which won’t be installed nor loaded: @@ -2926,85 +2926,45 @@ :PROPERTIES: :CUSTOM_ID: User_Configuration-Shortcuts-Files-206c2126 :END: - This category is mainly used for opening configuration files, but it is also - more generally for files-related commands. Let’s declare keybindings related - to my configuration files. Here is the list of them: - - [[file:bin.org][bin.org]] :: contains the source code of my custom scripts in my ~$PATH~ - - [[file:spacemacs.org][spacemacs.org]] :: this file, configuration of Emacs - - [[file:fish.org][fish.org]] :: configuration of my fish shell - - [[file:i3.org][i3.org]] :: configuration of my i3 installation - - [[file:index.org][index.org]] :: some various configuration files and index of this website - - [[file:polybar.org][polybar.org]] :: configuration for polybar - - [[file:picom.org][picom.org]] :: configuration for picom - - [[https://labs.phundrak.com/phundrak/dotfiles][README.org]] :: README of the yadm repo - I also have a keybinding for the following files: - - conlanging.org :: collection of ideas and references for conlanging - - elfeed.org :: where I store all the RSS sources for Elfeed - - journal.org :: my journal (which I don’t really use often tbh) - - notes.org :: to, well, take notes - - worldbuilding.org :: same as ~conlanging.org~ above. - Each of these files are accessible through a simple keybinding, and each one - of them has a description so the keybinding doesn’t show up as ~lambda~ with - ~which-keys~. So, a custom name for ~which-keys~ is specified in the Name - column. If a file is not specified, that means it is just a declaration for - a keybinding prefix. - - First, here are my keybindings for opening my private files described above: - #+NAME: private-files-open-shortcuts - | Keybinding | Name | File | - |------------+-------------------+---------------------------------| - | of | files | | - | ofb | blog.org | ~/org/blog/content-org/blog.org | - | ofC | conlanging.org | ~/org/conlanging.org | - | ofe | elfeed.org | ~/org/elfeed.org | - | ofj | journal.org | ~/org/journal.org | - | ofn | notes.org | ~/org/notes.org | - | ofw | worldbuilding.org | ~/org/worldbuilding.org | - - And here are my keybindings for opening config files: - #+NAME: config-files-open-shortcuts - | Keybinding | Name | File | - |------------+------------------+-------------------------------| - | ofc | config files | | - | ofca | awesome.org | ~/org/config/awesome.org | - | ofcb | bin.org | ~/org/config/bin.org | - | ofce | spacemacs.org | ~/org/config/spacemacs.org | - | ofcf | fish.org | ~/org/config/fish.org | - | ofci | index.org | ~/org/config/index.org | - | ofcI | installation.org | ~/org/config/installation.org | - | ofcp | polybar.org | ~/org/config/polybar.org | - | ofcP | picom.org | ~/org/config/picom.org | - | ofcr | yadm README | ~/README.org | - - #+NAME: shortcuts-gen - #+BEGIN_SRC emacs-lisp :tangle no :noweb yes :var table=[] :exports none :results replace - (concat (mapconcat (lambda (x) - (let* ((keybinding (nth 0 x)) - (name (nth 1 x))) - (if (string= "" name) "" - (format "(spacemacs/declare-prefix \"%s\"\t\"%s\")" - keybinding name)))) - table "\n") - "\n" - (format "(spacemacs/set-leader-keys\n%s)" - (mapconcat (lambda (x) - (let* ((keybinding (nth 0 x)) - (name (nth 1 x)) - (file (nth 2 x))) - (if (string= "" file) - (format "\t\;\; %s" name) - (format "\t\"%s\" (lambda () (interactive) (find-file \"%s\"))" - keybinding file)))) - table - "\n"))) + 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=. Let’s declare these + directories in a variable: + #+BEGIN_SRC emacs-lisp + (setq phundrak/org-directories '("~/org" + "~/Documents/university" + "~/Documents/conlanging")) #+END_SRC - Here is the actual code for these keybindings: - #+BEGIN_SRC emacs-lisp :noweb yes - <> - <> + With this established, let’s 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*")))) #+END_SRC + And that’s it! This should list all my org files under these directories and + give me fuzzy finding for these files. I just need to partially type the + name of the file I want to open and it should open without any issue. + *** Multiple cursors :PROPERTIES: :CUSTOM_ID: User_Configuration-Shortcuts-Multiple_cursors-83db7c9c