Add gist for executing code for certain files with find-file
This commit is contained in:
parent
ee5e3b6563
commit
ad450efe20
15
gists.org
15
gists.org
|
@ -623,6 +623,21 @@ An improved version was [[https://github.com/xenodium/dwim-shell-command/commit/
|
||||||
"\n")
|
"\n")
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
|
* Run code when opening a file with a certain name :emacs:
|
||||||
|
|
||||||
|
Based on an answer at the [[https://emacs.stackexchange.com/a/77480/34645][Emacs StackExchange]], to have some code executed for files that have no specific extension or mode set. For example, to have =yaml-mode= enabled when opening a /.clang-format/ file:
|
||||||
|
|
||||||
|
#+begin_src elisp :tangle gists/find-file-hook-for-certain-filenames.el
|
||||||
|
(setq my/setup-functions-alist '((".clang-format" . yaml-mode)))
|
||||||
|
|
||||||
|
(defun my/file-setup ()
|
||||||
|
(when-let* ((filename (file-name-nondirectory (buffer-file-name)))
|
||||||
|
(f (map-elt my/setup-functions-alist filename)))
|
||||||
|
(funcall f)))
|
||||||
|
|
||||||
|
(add-hook 'find-file-hook #'my/file-setup)
|
||||||
|
#+end_src
|
||||||
|
|
||||||
* Meta
|
* Meta
|
||||||
** License
|
** License
|
||||||
|
|
||||||
|
|
8
gists/find-file-hook-for-certain-filenames.el
Normal file
8
gists/find-file-hook-for-certain-filenames.el
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
(setq my/setup-functions-alist '((".clang-format" . yaml-mode)))
|
||||||
|
|
||||||
|
(defun my/file-setup ()
|
||||||
|
(when-let* ((filename (file-name-nondirectory (buffer-file-name)))
|
||||||
|
(f (map-elt my/setup-functions-alist filename)))
|
||||||
|
(funcall f)))
|
||||||
|
|
||||||
|
(add-hook 'find-file-hook #'my/file-setup)
|
Loading…
Reference in a new issue