Browse Source

Emacs: Switch package projectile -> project.el

master
Riyyi 2 years ago
parent
commit
28c152ba22
  1. 32
      .config/emacs/config.org
  2. 55
      .config/emacs/config/development.org
  3. 4
      .config/emacs/config/org-mode.org
  4. 4
      .config/emacs/config/selection.org
  5. 20
      .config/emacs/config/ui.org

32
.config/emacs/config.org

@ -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)
@ -1034,8 +1059,8 @@ 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")
;; Quit ;; Quit
"q" '(:ignore t :which-key "quit") "q" '(:ignore t :which-key "quit")
@ -1056,9 +1081,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")

55
.config/emacs/config/development.org

@ -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

4
.config/emacs/config/org-mode.org

@ -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

4
.config/emacs/config/selection.org

@ -40,7 +40,5 @@
(marginalia-mode)) (marginalia-mode))
(use-package consult (use-package consult
:after selectrum :after selectrum)
:config
(setq consult-project-root-function #'dot/find-project-root))
#+END_SRC #+END_SRC

20
.config/emacs/config/ui.org

@ -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

Loading…
Cancel
Save