Compare commits

...
3 Commits
Author SHA1 Message Date
Riyyi 9049b130a8 Emacs: Use more of the consult package 2022-07-31 16:06:04 +02:00
Riyyi 4389dce613 Emacs: Change git leader key prefix 2022-07-31 14:56:56 +02:00
Riyyi 28c152ba22 Emacs: Switch package projectile -> project.el 2022-07-31 13:00:41 +02:00
5 changed files with 147 additions and 74 deletions
+72 -44
View File
@@ -463,6 +463,31 @@ Functions that only use built-in Emacs functionality.
(interactive) (interactive)
(org-babel-load-file (concat dot-emacs-dir "/config.org"))) (org-babel-load-file (concat dot-emacs-dir "/config.org")))
;; Reference: http://turingmachine.org/bl/2013-05-29-recursively-listing-directories-in-elisp.html
(defun dot/directory-files-recursively-depth (dir regexp include-directories maxdepth)
"Depth limited variant of the built-in `directory-files-recursively'."
(let ((result '())
(current-directory-list (directory-files dir t)))
(dolist (path current-directory-list)
(cond
((and (file-regular-p path)
(file-readable-p path)
(string-match regexp path))
(setq result (cons path result)))
((and (file-directory-p path)
(file-readable-p path)
(not (string-equal "/.." (substring path -3)))
(not (string-equal "/." (substring path -2))))
(when (and include-directories
(string-match regexp path))
(setq result (cons path result)))
(when (> maxdepth 1)
(setq result (append (nreverse (dot/directory-files-recursively-depth
path regexp include-directories (- maxdepth 1)))
result))))
(t)))
(reverse result)))
(defun dot/dired-find-file () (defun dot/dired-find-file ()
"In Dired, visit the file or directory named on this line." "In Dired, visit the file or directory named on this line."
(interactive) (interactive)
@@ -482,12 +507,6 @@ Functions that only use built-in Emacs functionality.
(directory-files-recursively dot-emacs-dir "")))) (directory-files-recursively dot-emacs-dir ""))))
(find-file (completing-read "Find file (emacs): " files nil t)))) (find-file (completing-read "Find file (emacs): " files nil t))))
(defun dot/find-file-recentf ()
"Use `completing-read' to open a recent file."
(interactive)
(let ((files (mapcar 'abbreviate-file-name recentf-list)))
(find-file (completing-read "Find file (recent): " files nil t))))
(defun dot/indent-buffer () (defun dot/indent-buffer ()
"Indent each nonblank line in the buffer." "Indent each nonblank line in the buffer."
(interactive) (interactive)
@@ -928,7 +947,7 @@ General.el ~leader key binds.
(space-leader (space-leader
"SPC" '(dot/M-x :which-key "Execute command") "SPC" '(dot/M-x :which-key "Execute command")
"RET" '(bookmark-jump :which-key "Jump to bookmark") "RET" '(consult-bookmark :which-key "Go to bookmark")
;; Apps ;; Apps
"a" '(:ignore t :which-key "apps") "a" '(:ignore t :which-key "apps")
@@ -938,7 +957,7 @@ General.el ~leader key binds.
;; Buffer / bookmark ;; Buffer / bookmark
"b" '(:ignore t :which-key "buffer/bookmark") "b" '(:ignore t :which-key "buffer/bookmark")
"b a" '(auto-revert-mode :which-key "Auto revert buffer") "b a" '(auto-revert-mode :which-key "Auto revert buffer")
"b b" '(switch-to-buffer :which-key "Switch buffer") "b b" '(consult-buffer :which-key "Switch buffer")
"b d" '(dot/dashboard-goto :which-key "Dashboard") "b d" '(dot/dashboard-goto :which-key "Dashboard")
"b k" '(kill-current-buffer :which-key "Kill buffer") "b k" '(kill-current-buffer :which-key "Kill buffer")
"b m" '(bookmark-set :which-key "Make bookmark") "b m" '(bookmark-set :which-key "Make bookmark")
@@ -968,44 +987,25 @@ General.el ~leader key binds.
;; File ;; File
"f" '(:ignore t :which-key "file") "f" '(:ignore t :which-key "file")
"f e" '(:ignore t :which-key "emacs")
"f e c" '(dot/config-visit :which-key "Config visit")
"f e f" '(dot/find-file-emacsd :which-key "Find emacs file")
"f e r" '(dot/config-reload :which-key "Config reload")
"f d" '(dired :which-key "Find directory") "f d" '(dired :which-key "Find directory")
"f f" '(dot/find-file-in-project-root :which-key "Find file") "f f" '(dot/find-file-in-project-root :which-key "Find file")
"f o" '(ff-find-other-file :which-key "Find header/source file") "f o" '(ff-find-other-file :which-key "Find header/source file")
"f r" '(dot/find-file-recentf :which-key "Find recent file ") "f r" '(consult-recent-file :which-key "Find recent file")
"f R" '(rename-file-and-buffer :which-key "Rename file") "f R" '(rename-file-and-buffer :which-key "Rename file")
"f s" '(basic-save-buffer :which-key "Save file") "f s" '(basic-save-buffer :which-key "Save file")
"f S" '(write-file :which-key "Save file as...") "f S" '(write-file :which-key "Save file as...")
"f u" '(dot/sudo-find-file :which-key "Sudo find file") "f u" '(dot/sudo-find-file :which-key "Sudo find file")
"f U" '(dot/sudo-this-file :which-key "Sudo this file") "f U" '(dot/sudo-this-file :which-key "Sudo this file")
"f e" '(:ignore t :which-key "emacs")
"f e c" '(dot/config-visit :which-key "Config visit")
"f e f" '(dot/find-file-emacsd :which-key "Find emacs file")
"f e r" '(dot/config-reload :which-key "Config reload")
;; Git ;; Go to
"g" '(:ignore t :which-key "git") "g" '(:ignore t :which-key "goto")
"g b" '(magit-branch-checkout :which-key "Magit switch branch") "g b" '(consult-bookmark :which-key "Go to bookmark")
"g B" '(magit-blame-addition :which-key "Magit blame") "g f" '(consult-flycheck :which-key "Go to flycheck error")
"g c" '(:ignore t :which-key "create") "g m" '(consult-mark :which-key "Go to marker")
"g c c" '(magit-commit-create :which-key "Commit")
"g c b" '(magit-branch-and-checkout :which-key "Branch")
"g c r" '(magit-init :which-key "Initialize repo")
"g C" '(magit-clone :which-key "Magit clone")
"g f" '(:ignore t :which-key "file")
"g f c" '(magit-find-git-config-file :which-key "Find gitconfig file")
"g f D" '(magit-file-delete :which-key "Delete file")
"g f f" '(magit-find-file :which-key "Find file")
"g f R" '(magit-file-rename :which-key "Rename file")
"g F" '(magit-fetch :which-key "Magit fetch")
"g g" '(magit-status :which-key "Magit status")
"g G" '(magit-status-here :which-key "Magit status here")
"g l" '(:ignore t :which-key "list")
"g l r" '(magit-list-repositories :which-key "List repositories")
"g l s" '(magit-list-submodules :which-key "List submodules")
"g L" '(magit-log :which-key "Magit log")
"g s" '(magit-show-commit :which-key "Magit show commit")
"g S" '(magit-stage-file :which-key "Stage file")
"g U" '(magit-unstage-file :which-key "Unstage file")
;; Help ;; Help
"h" '(:keymap help-map :which-key "help") "h" '(:keymap help-map :which-key "help")
@@ -1034,8 +1034,11 @@ General.el ~leader key binds.
"n r r" '(org-roam-buffer-toggle :which-key "Toggle buffer") "n r r" '(org-roam-buffer-toggle :which-key "Toggle buffer")
"n r s" '(org-roam-ui-mode :which-key "Toggle server") "n r s" '(org-roam-ui-mode :which-key "Toggle server")
;; Projectile ;; Project
"p" '(:keymap projectile-command-map :package projectile :which-key "projectile") "p" '(:keymap project-prefix-map :which-key "project")
"p b" '(consult-project-buffer :which-key "project-switch-buffer")
"p f" '(consult-project-extra-find :which-key "project-find-file")
"p g" '(consult-grep :which-key "project-find-regexp")
;; Quit ;; Quit
"q" '(:ignore t :which-key "quit") "q" '(:ignore t :which-key "quit")
@@ -1047,7 +1050,6 @@ General.el ~leader key binds.
;; Search ;; Search
"s" '(:ignore t :which-key "search") "s" '(:ignore t :which-key "search")
"s a" '(avy-goto-char-timer :which-key "Avy goto char") "s a" '(avy-goto-char-timer :which-key "Avy goto char")
"s b" '(bookmark-jump :which-key "Jump to bookmark")
"s f" '(consult-find :which-key "Search file") "s f" '(consult-find :which-key "Search file")
"s l" '(avy-goto-line :which-key "Avy goto line") "s l" '(avy-goto-line :which-key "Avy goto line")
"s p" '(consult-grep :which-key "Search project") "s p" '(consult-grep :which-key "Search project")
@@ -1056,9 +1058,8 @@ General.el ~leader key binds.
;; Tabs / toggle ;; Tabs / toggle
"t" '(:ignore t :which-key "tabs/toggle") "t" '(:ignore t :which-key "tabs/toggle")
"t b" '(centaur-tabs-group-buffer-groups :which-key "Group tabs by buffer")
"t f" '(dot/toggle-fringe :which-key "Toggle fringe") "t f" '(dot/toggle-fringe :which-key "Toggle fringe")
"t p" '(centaur-tabs-group-by-projectile-project :which-key "Group tabs by project") "t g" '(centaur-tabs-switch-group :which-key "Switch tab group")
"t h" '(centaur-tabs-backward-group :which-key "Tab backward group") "t h" '(centaur-tabs-backward-group :which-key "Tab backward group")
"t j" '(centaur-tabs-select-end-tab :which-key "Tab select first") "t j" '(centaur-tabs-select-end-tab :which-key "Tab select first")
"t k" '(centaur-tabs-select-beg-tab :which-key "Tab select last") "t k" '(centaur-tabs-select-beg-tab :which-key "Tab select last")
@@ -1069,6 +1070,31 @@ General.el ~leader key binds.
;; Update packages ;; Update packages
"U" '(dot/update-packages :which-key "Update packages") "U" '(dot/update-packages :which-key "Update packages")
;; Version control
"v" '(:ignore t :which-key "git")
"v b" '(magit-branch-checkout :which-key "Magit switch branch")
"v B" '(magit-blame-addition :which-key "Magit blame")
"v C" '(magit-clone :which-key "Magit clone")
"v F" '(magit-fetch :which-key "Magit fetch")
"v L" '(magit-log :which-key "Magit log")
"v s" '(magit-show-commit :which-key "Magit show commit")
"v S" '(magit-stage-file :which-key "Stage file")
"v U" '(magit-unstage-file :which-key "Unstage file")
"v v" '(magit-status :which-key "Magit status")
"v V" '(magit-status-here :which-key "Magit status here")
"v c" '(:ignore t :which-key "create")
"v c c" '(magit-commit-create :which-key "Commit")
"v c b" '(magit-branch-and-checkout :which-key "Branch")
"v c r" '(magit-init :which-key "Initialize repo")
"v f" '(:ignore t :which-key "file")
"v f c" '(magit-find-git-config-file :which-key "Find gitconfig file")
"v f D" '(magit-file-delete :which-key "Delete file")
"v f f" '(magit-find-file :which-key "Find file")
"v f R" '(magit-file-rename :which-key "Rename file")
"v l" '(:ignore t :which-key "list")
"v l r" '(magit-list-repositories :which-key "List repositories")
"v l s" '(magit-list-submodules :which-key "List submodules")
;; Window ;; Window
"w" '(:ignore t :which-key "window") "w" '(:ignore t :which-key "window")
"w +" '(evil-window-increase-height :which-key "Increase window height") "w +" '(evil-window-increase-height :which-key "Increase window height")
@@ -1131,6 +1157,10 @@ https://github.com/suyashbire1/emacs.d/blob/master/init.el
"'" '(org-edit-special :which-key "Org edit") "'" '(org-edit-special :which-key "Org edit")
"e" '(org-export-dispatch :which-key "Org export") "e" '(org-export-dispatch :which-key "Org export")
"o" '(org-open-at-point :which-key "Org open at point") "o" '(org-open-at-point :which-key "Org open at point")
"q" '(org-set-tags-command :which-key "Org tags")
"g" '(:ignore t :which-key "goto")
"g o" '(consult-outline :which-key "Org go to heading")
"i" '(:ignore t :which-key "insert") "i" '(:ignore t :which-key "insert")
"i c" '(org-table-insert-column :which-key "Insert table column") "i c" '(org-table-insert-column :which-key "Insert table column")
@@ -1145,8 +1175,6 @@ https://github.com/suyashbire1/emacs.d/blob/master/init.el
"l s" '(org-store-link :which-key "Store link") "l s" '(org-store-link :which-key "Store link")
"l S" '(org-insert-last-stored-link :which-key "Insert stored link") "l S" '(org-insert-last-stored-link :which-key "Insert stored link")
"q" '(org-set-tags-command :which-key "Org tags")
"s" '(:ignore t :which-key "tree/subtree") "s" '(:ignore t :which-key "tree/subtree")
"s h" '(org-promote-subtree :which-key "Org promote subtree") "s h" '(org-promote-subtree :which-key "Org promote subtree")
"s j" '(org-metadown :which-key "Org move subtree down") "s j" '(org-metadown :which-key "Org move subtree down")
+40 -15
View File
@@ -5,7 +5,7 @@
** Table of Contents :toc_4: ** Table of Contents :toc_4:
- [[#company][Company]] - [[#company][Company]]
- [[#git][Git]] - [[#git][Git]]
- [[#projectile][Projectile]] - [[#project][Project]]
- [[#languages][Languages]] - [[#languages][Languages]]
- [[#language-server-support][Language Server Support]] - [[#language-server-support][Language Server Support]]
- [[#debug-adapter-support][Debug Adapter Support]] - [[#debug-adapter-support][Debug Adapter Support]]
@@ -107,28 +107,29 @@ GLSL integration with company requires the package: ~glslang~.
(put 'magit-log-select-pick :advertised-binding [?\M-c]) (put 'magit-log-select-pick :advertised-binding [?\M-c])
(put 'magit-log-select-quit :advertised-binding [?\M-k])) (put 'magit-log-select-quit :advertised-binding [?\M-k]))
#+END_SRC #+END_SRC
** Projectile
** Project
Project manager. Project manager.
[[https://michael.stapelberg.ch/posts/2021-04-02-emacs-project-override/][Adding to project.el project directory detection]].
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(use-package projectile (use-package project
:defer t :defer t
:init (setq project-list-file (concat dot-cache-dir "/projects"))
:config :config
(setq projectile-cache-file (concat dot-cache-dir "/projectile.cache")) (defun dot/project-find (dir)
(setq projectile-completion-system 'default) (let ((root (locate-dominating-file dir ".project")))
(setq projectile-enable-caching t) (and root (cons 'vc root))))
(setq projectile-indexing-method 'hybrid) (add-hook 'project-find-functions #'dot/project-find)
(setq projectile-known-projects-file (concat dot-cache-dir "/projectile-bookmarks.eld"))
(setq projectile-project-search-path '("~"))
(setq projectile-sort-order 'recentf)
(defun dot/find-project-root () (defun dot/find-project-root ()
"Return root of the project, determined by `.git/' and `.projectile', "Return root of the project, determined by `.git/' and `.project',
`default-directory' otherwise." `default-directory' otherwise."
(let ((search-directory (projectile-project-root))) (let ((project (project-current)))
(if search-directory (if project
search-directory (project-root project)
default-directory))) default-directory)))
(defun dot/find-file-in-project-root () (defun dot/find-file-in-project-root ()
@@ -137,7 +138,31 @@ Project manager.
(let ((default-directory (dot/find-project-root))) (let ((default-directory (dot/find-project-root)))
(call-interactively 'find-file))) (call-interactively 'find-file)))
(projectile-mode)) (defun dot/project-remember-projects-under (dir maxdepth)
"Index all projects below directory DIR recursively, until MAXDEPTH."
(let ((files (mapcar 'file-name-directory
(dot/directory-files-recursively-depth
dir "\\.git$\\|\\.project$" t maxdepth))))
(dolist (path files)
(project-remember-projects-under path))))
(unless (file-exists-p project-list-file)
(project-remember-projects-under "~/dotfiles")
(dot/project-remember-projects-under "~/code" 4))
(defun dot/project-project-name ()
"Return project name."
(let ((project (project-current)))
(if project
(file-name-nondirectory (directory-file-name (project-root project)))
"-")))
(defun dot/project-save-project-buffers ()
"Save all project buffers."
(interactive)
(let ((buffers (cl-remove-if (lambda (buffer) (not (buffer-file-name buffer)))
(project-buffers (project-current)))))
(save-some-buffers t (lambda () (member (current-buffer) buffers))))))
#+END_SRC #+END_SRC
** Languages ** Languages
+2 -2
View File
@@ -23,12 +23,12 @@
(setq tex-indent-basic 4))) (setq tex-indent-basic 4)))
:config :config
(with-eval-after-load 'projectile (with-eval-after-load 'project
(defun compile-latex () (defun compile-latex ()
"Compile LaTeX project." "Compile LaTeX project."
(interactive) (interactive)
(let ((default-directory (dot/find-project-root))) (let ((default-directory (dot/find-project-root)))
(projectile-save-project-buffers) (dot/project-save-project-buffers)
(shell-command "make"))))) (shell-command "make")))))
#+END_SRC #+END_SRC
+8 -2
View File
@@ -41,6 +41,12 @@
(use-package consult (use-package consult
:after selectrum :after selectrum
:config :config (setq consult-narrow-key (kbd "?")))
(setq consult-project-root-function #'dot/find-project-root))
(use-package consult-flycheck
:after (consult flycheck))
(use-package consult-project-extra
:after (consult project)
:config (setq project-switch-commands 'consult-project-extra-find))
#+END_SRC #+END_SRC
+17 -3
View File
@@ -53,17 +53,30 @@ Places buffers as tabs in a bar at the top of the frame.
(setq centaur-tabs-set-modified-marker t) (setq centaur-tabs-set-modified-marker t)
(setq centaur-tabs-style "slant") (setq centaur-tabs-style "slant")
(setq centaur-tabs-project-buffer-group-calc nil)
(defun centaur-tabs-buffer-groups () (defun centaur-tabs-buffer-groups ()
"Organize tabs into groups by buffer." "Organize tabs into groups by buffer."
(unless centaur-tabs-project-buffer-group-calc
(set (make-local-variable 'centaur-tabs-project-buffer-group-calc)
(list (list
(cond (cond
((string-equal "*" (substring (buffer-name) 0 1)) "Emacs") ((string-equal "*" (substring (buffer-name) 0 1)) "Emacs")
((or (memq major-mode '(magit-process-mode
magit-status-mode
magit-diff-mode
magit-log-mode
magit-file-mode
magit-blob-mode
magit-blame-mode))
(string= (buffer-name) "COMMIT_EDITMSG")) "Magit")
((project-current) (dot/project-project-name))
((memq major-mode '(org-mode ((memq major-mode '(org-mode
emacs-lisp-mode)) "Org Mode") emacs-lisp-mode)) "Org Mode")
((derived-mode-p 'dired-mode) "Dired") ((derived-mode-p 'dired-mode) "Dired")
((derived-mode-p 'prog-mode ((derived-mode-p 'prog-mode
'text-mode) "Editing") 'text-mode) "Editing")
(t "User")))) (t "Other")))))
(symbol-value 'centaur-tabs-project-buffer-group-calc))
(defun centaur-tabs-hide-tab (buffer) (defun centaur-tabs-hide-tab (buffer)
"Hide from the tab bar by BUFFER name." "Hide from the tab bar by BUFFER name."
@@ -137,6 +150,7 @@ Places buffers as tabs in a bar at the top of the frame.
(setq dashboard-banner-logo-title "GNU Emacs master race!") (setq dashboard-banner-logo-title "GNU Emacs master race!")
(setq dashboard-center-content t) (setq dashboard-center-content t)
(setq dashboard-page-separator "\n\f\n") (setq dashboard-page-separator "\n\f\n")
(setq dashboard-projects-backend 'project-el)
(setq dashboard-set-file-icons t) (setq dashboard-set-file-icons t)
(setq dashboard-set-footer nil) (setq dashboard-set-footer nil)
(setq dashboard-set-heading-icons t) (setq dashboard-set-heading-icons t)
@@ -196,7 +210,7 @@ Provides Emacs with a file tree.
:init :init
;; This needs to be in init to actually start loading the package ;; This needs to be in init to actually start loading the package
(with-eval-after-load 'projectile (with-eval-after-load 'project
(defun neotree-toggle-in-project-root () (defun neotree-toggle-in-project-root ()
"Toggle Neotree in project root." "Toggle Neotree in project root."
(interactive) (interactive)
@@ -224,7 +238,7 @@ Emacs mode line replacement.
(accent . (telephone-line-erc-modified-channels-segment (accent . (telephone-line-erc-modified-channels-segment
telephone-line-process-segment telephone-line-process-segment
telephone-line-buffer-segment)) telephone-line-buffer-segment))
(nil . (telephone-line-projectile-segment)))) (nil . (telephone-line-project-segment))))
(telephone-line-mode)) (telephone-line-mode))
#+END_SRC #+END_SRC