Add some binds to quickly open projects as well as buffers

This commit is contained in:
Evie Litherland-Smith 2024-02-23 11:45:34 +00:00
parent a338e54f0e
commit e2e4fab5a8

View file

@ -14,7 +14,7 @@
#+begin_src emacs-lisp #+begin_src emacs-lisp
;; Config file shortcut ;; Config file shortcut
(defun my/open-init-file () (defun my/open-init-file ()
"Open emacs init file" "Open emacs init file."
(interactive) (interactive)
(find-file (locate-user-emacs-file "init.el"))) (find-file (locate-user-emacs-file "init.el")))
(keymap-global-set "C-c w c" #'my/open-init-file) (keymap-global-set "C-c w c" #'my/open-init-file)
@ -23,7 +23,7 @@
#+begin_src emacs-lisp #+begin_src emacs-lisp
;; NixOS flake shortcut ;; NixOS flake shortcut
(defun my/open-nixos-flake () (defun my/open-nixos-flake ()
"Open NixOS system config flake" "Open NixOS system config flake."
(interactive) (interactive)
(let ((flake "/etc/nixos/flake.nix")) (let ((flake "/etc/nixos/flake.nix"))
(if (file-exists-p flake) (if (file-exists-p flake)
@ -34,43 +34,43 @@
** Templates file ** Templates file
#+begin_src emacs-lisp #+begin_src emacs-lisp
;; Tempel template file shortcut ;; Tempel template file shortcut
(with-eval-after-load 'tempel (defun my/open-template-file ()
(defun my/open-template-file () "Open `tempel' template file."
"Open `tempel' template file" (interactive)
(interactive) (require 'tempel)
(find-file tempel-path)) (find-file tempel-path))
(keymap-global-set "C-c w t" #'my/open-template-file)) (keymap-global-set "C-c w t" #'my/open-template-file)
#+end_src #+end_src
** Org directory ** Org directory
#+begin_src emacs-lisp #+begin_src emacs-lisp
;; Org directory shortcut ;; Org directory shortcut
(with-eval-after-load 'org (defun my/open-org-directory ()
(defun my/open-org-directory () "Open base org-mode directory in dired."
"Open base org-mode directory in dired" (interactive)
(interactive) (require 'org)
(find-file org-directory)) (find-file org-directory))
(keymap-global-set "C-c w o" #'my/open-org-directory)) (keymap-global-set "C-c w o" #'my/open-org-directory)
#+end_src #+end_src
** RSS feeds file ** RSS feeds file
#+begin_src emacs-lisp #+begin_src emacs-lisp
;; Elfeed feeds file shortcut ;; Elfeed feeds file shortcut
(with-eval-after-load 'org (defun my/open-feeds-file ()
(defun my/open-feeds-file () "Open org file containing elfeed sources."
"Open org file containing elfeed sources" (interactive)
(interactive) (require 'org)
(require 'elfeed) (require 'elfeed)
(require 'elfeed-org) (require 'elfeed-org)
(find-file (expand-file-name "feeds.org" elfeed-base-directory)))) (find-file (expand-file-name "feeds.org" elfeed-base-directory)))
(keymap-global-set "C-c w f" #'my/open-feeds-file) (keymap-global-set "C-c w f" #'my/open-feeds-file)
#+end_src #+end_src
** Documents and Downloads ** Documents and Downloads
#+begin_src emacs-lisp #+begin_src emacs-lisp
(defun my/open-documents-directory () (defun my/open-documents-directory ()
"Open Documents directory" "Open Documents directory."
(interactive) (interactive)
(find-file "~/Documents/")) (find-file "~/Documents/"))
(defun my/open-downloads-directory () (defun my/open-downloads-directory ()
"Open Downloads directory" "Open Downloads directory."
(interactive) (interactive)
(find-file "~/Downloads/")) (find-file "~/Downloads/"))
(keymap-global-set "C-c w d" #'my/open-documents-directory) (keymap-global-set "C-c w d" #'my/open-documents-directory)
@ -78,14 +78,36 @@
#+end_src #+end_src
** Projects directory ** Projects directory
#+begin_src emacs-lisp #+begin_src emacs-lisp
(with-eval-after-load 'magit (defun my/open-projects-directory ()
(defun my/open-projects-directory () "Open Projects directory.
"Open Projects directory.
Try `magit-clone-default-directory' if available, fall back to Try `magit-clone-default-directory' if available, fall back to
~/Projects otherwise." ~/Projects otherwise."
(interactive) (interactive)
(find-file (if magit-clone-default-directory (require 'magit)
magit-clone-default-directory (find-file (if magit-clone-default-directory
"~/Projects/"))) magit-clone-default-directory
(keymap-global-set "C-c w p" #'my/open-projects-directory)) "~/Projects/")))
(keymap-global-set "C-c w p" #'my/open-projects-directory)
#+end_src
* Common project shortcuts
** NixOS
#+begin_src emacs-lisp
(defun my/open-nixos-project ()
"Open NixOS config project."
(interactive)
(require 'project)
(let ((nixos "/etc/nixos/"))
(if (file-directory-p nixos)
(project-switch-project nixos)
(warn (concat nixos " not found")))))
(keymap-global-set "C-c p n" #'my/open-nixos-project)
#+end_src
** emacs
#+begin_src emacs-lisp
(defun my/open-emacs-project ()
"Open Emacs config project."
(interactive)
(require 'project)
(project-switch-project user-emacs-directory))
(keymap-global-set "C-c p e" #'my/open-emacs-project)
#+end_src #+end_src