diff --git a/.emacs.d/init.el b/.emacs.d/init.el index d8ec119..cb4aceb 100644 --- a/.emacs.d/init.el +++ b/.emacs.d/init.el @@ -26,7 +26,7 @@ (require 'init-search) (require 'init-navigation) (require 'init-windows) -(require 'init-projectile) +(require 'init-project) (require 'init-modeline) (require 'init-dashboard) (require 'init-completion) diff --git a/.emacs.d/lisp/init-clojure.el b/.emacs.d/lisp/init-clojure.el index 0f19c15..719f2ca 100644 --- a/.emacs.d/lisp/init-clojure.el +++ b/.emacs.d/lisp/init-clojure.el @@ -30,7 +30,6 @@ (use-package cider :diminish - :after key-chord :config (setq cider-repl-pop-to-buffer-on-connect 'display-only cider-repl-display-help-banner nil @@ -44,8 +43,6 @@ cider-repl-history-file "~/.emacs.d/cider-history" nrepl-log-messages t clojure-toplevel-inside-comment-form t) - (key-chord-define-global "??" 'cider-xref-fn-refs-select) - (key-chord-define-global "qq" 'cider-xref-fn-refs) (unbind-key "C-c C-l" cider-mode-map) :bind (:map cider-mode-map ("C-c M-l" . cider-load-file)) :hook diff --git a/.emacs.d/lisp/init-crux.el b/.emacs.d/lisp/init-crux.el index 93e5802..df4ade1 100644 --- a/.emacs.d/lisp/init-crux.el +++ b/.emacs.d/lisp/init-crux.el @@ -3,9 +3,6 @@ ;;; Code: (use-package crux - :after key-chord - :config - (key-chord-define-global "JJ" 'crux-switch-to-previous-buffer) :bind ("C-^" . crux-top-join-line) ("C-" . crux-kill-line-backwards) diff --git a/.emacs.d/lisp/init-dashboard.el b/.emacs.d/lisp/init-dashboard.el index 30285a5..63cacc6 100644 --- a/.emacs.d/lisp/init-dashboard.el +++ b/.emacs.d/lisp/init-dashboard.el @@ -8,8 +8,8 @@ dashboard-startup-banner 'logo dashboard-set-footer nil dashboard-week-agenda t - dashboard-projects-backend 'projectile - dashboard-projects-switch-function 'projectile-persp-switch-project + dashboard-projects-backend 'project-el + dashboard-projects-switch-function 'switch-project dashboard-items '((recents . 15) (bookmarks . 5) (projects . 5) diff --git a/.emacs.d/lisp/init-editor.el b/.emacs.d/lisp/init-editor.el index d1d80cb..1946b46 100644 --- a/.emacs.d/lisp/init-editor.el +++ b/.emacs.d/lisp/init-editor.el @@ -150,7 +150,6 @@ and file 'filename' will be opened and cursor set on line 'linenumber'" (use-package undo-tree :diminish - :after key-chord :config (global-undo-tree-mode) :custom diff --git a/.emacs.d/lisp/init-kill.el b/.emacs.d/lisp/init-kill.el index ceada0d..2cc5ac7 100644 --- a/.emacs.d/lisp/init-kill.el +++ b/.emacs.d/lisp/init-kill.el @@ -4,10 +4,8 @@ ;;; Code: (use-package browse-kill-ring - :after key-chord :config - (browse-kill-ring-default-keybindings) - (key-chord-define-global "yy" 'browse-kill-ring)) + (browse-kill-ring-default-keybindings)) (use-package easy-kill :bind diff --git a/.emacs.d/lisp/init-lsp.el b/.emacs.d/lisp/init-lsp.el index 4b72759..e66eb24 100644 --- a/.emacs.d/lisp/init-lsp.el +++ b/.emacs.d/lisp/init-lsp.el @@ -6,9 +6,10 @@ :config (require 'lsp-ui-imenu)) +(use-package lsp-treemacs) + (use-package lsp-mode :diminish - :after key-chord :hook (clojure-mode . lsp) :config (if (eq system-type 'darwin) @@ -19,11 +20,12 @@ lsp-ui-peek-enable t lsp-ui-peek-always-show t lsp-ui-doc-delay 1 - lsp-lens-enable nil + lsp-lens-enable t lsp-ui-doc-enable t lsp-ui-doc-show-with-cursor t lsp-ui-doc-show-with-mouse t - lsp-headerline-breadcrumb-enable nil + lsp-headerline-breadcrumb-enable t + lsp-headerline-breadcrumb-enable-diagnostics nil lsp-enable-symbol-highlighting t lsp-ui-sideline-show-diagnostics t lsp-ui-sideline-show-code-actions nil @@ -34,16 +36,10 @@ ;; user cider for indendation and completion instead lsp-enable-indentation nil lsp-completion-enable nil) - (key-chord-define-global "QQ" 'lsp-find-references) - (key-chord-define-global "PP" 'lsp-peek-find-references) - (key-chord-define-global "GG" 'lsp-find-definition) - (key-chord-define-global "DD" 'lsp-peek-find-definitions) :bind (:map lsp-ui-mode-map ([remap xref-find-definitions] . lsp-ui-peek-find-definitions) ([remap xref-find-references] . lsp-ui-peek-find-references))) -(use-package lsp-treemacs) - (provide 'init-lsp) ;;; init-lsp.el ends here diff --git a/.emacs.d/lisp/init-minibuffer.el b/.emacs.d/lisp/init-minibuffer.el index 3bdfc11..f1d81a4 100644 --- a/.emacs.d/lisp/init-minibuffer.el +++ b/.emacs.d/lisp/init-minibuffer.el @@ -52,8 +52,6 @@ (select-window (minibuffer-selected-window)) (select-window (active-minibuffer-window)))) - (key-chord-define-global "XX" 'to-and-fro-minibuffer) - ;(key-chord-define-global ">>" 'preview-from-outside) :bind (("C-M-<" . up-from-outside) ("C-M->" . down-from-outside) ("C-M-+" . preview-from-outside) @@ -66,7 +64,7 @@ :init (defvar switching-project nil) (defun vertico-directory-enter-or-switch-project () - "Wrapper around vertico-directory-enter that plays nicely with Projectile." + "Wrapper around vertico-directory-enter that plays nicely with adding projects." (interactive) (if switching-project (vertico-exit) @@ -74,7 +72,7 @@ (defun read-project (orig &rest args) (let ((switching-project t)) (apply orig args))) - (advice-add 'projectile-completing-read :around + (advice-add 'project-prompt-project-dir :around 'read-project) :config (defun vertico-directory-slash () @@ -106,7 +104,6 @@ :bind ("M-P" . vertico-repeat)) (use-package consult - :after projectile :bind (;; C-c bindings (mode-specific-map) ("C-c h" . consult-history) ("C-c m" . consult-mode-command) @@ -189,15 +186,39 @@ (defun consult-line-symbol-at-point () (interactive) (consult-line (thing-at-point 'symbol))) + (defvar consult--fd-command nil) + (defun consult--fd-builder (input) + (unless consult--fd-command + (setq consult--fd-command + (if (eq 0 (call-process-shell-command "fdfind")) + "fdfind" + "fd"))) + (pcase-let* ((`(,arg . ,opts) (consult--command-split input)) + (`(,re . ,hl) (funcall consult--regexp-compiler + arg 'extended))) + (when re + (list :command (append + (list consult--fd-command + "--color=never" "--full-path" + (consult--join-regexps re 'extended)) + opts) + :highlight hl)))) + + (defun consult-fd (&optional dir initial) + (interactive "P") + (let* ((prompt-dir (consult--directory-prompt "Fd" dir)) + (default-directory (cdr prompt-dir))) + (find-file (consult--find (car prompt-dir) #'consult--fd-builder initial)))) ;; Add these here, as we have two bindings for search map (M-s and C-c s) - (define-key search-map "f" 'consult-find) - (define-key search-map "F" 'consult-locate) + (define-key search-map "f" 'consult-fd) + (define-key search-map "F" 'consult-find) + (define-key search-map (kbd "M-f") 'consult-locate) (define-key search-map "g" 'consult-grep) (define-key search-map "G" 'consult-git-grep) (define-key search-map "r" 'consult-ripgrep) (define-key search-map "R" 'consult-ripgrep-auto-preview) - (define-key search-map "M-r" 'consult-ripgrep-unrestricted) + (define-key search-map (kbd "M-r") 'consult-ripgrep-unrestricted) (define-key search-map "*" 'consult-ripgrep-symbol-at-point) (define-key search-map "z" 'consult-z-ripgrep) (define-key search-map "l" 'consult-line) @@ -231,20 +252,78 @@ ;; You may want to use `embark-prefix-help-command' or which-key instead. ;; (define-key consult-narrow-map (vconcat consult-narrow-key "?") #'consult-narrow-help) - (autoload 'projectile-project-root "projectile") - (setq consult-project-root-function #'projectile-project-root) + (setq consult-project-root-function + (lambda () + (when-let (project (project-current)) + (car (project-roots project))))) + + ;; Switch perspective when switching buffer if needed + (setq consult--display-buffer #'persp-switch-to-buffer) (defvar consult-initial-narrow-config - '((consult-buffer . ?p) - (consult-buffer-no-preview . ?p))) + '((consult-buffer . ?x) + (consult-buffer-no-preview . ?x))) ;; Add initial narrowing hook (defun consult-initial-narrow () (when-let (key (alist-get this-command consult-initial-narrow-config)) (setq unread-command-events (append unread-command-events (list key 32))))) (add-hook 'minibuffer-setup-hook #'consult-initial-narrow) - (when (and (eq system-type 'darwin) (string-match-p "^find" consult-find-command)) - (setq consult-find-command (concat "g" consult-find-command))) + (when (and (eq system-type 'darwin) (string-match-p "^find" consult-find-args)) + (setq consult-find-args (concat "g" consult-find-args))) + + ;; Use fd that that we aren't just getting recentf, but also respect .gitignore + (setq consult--source-project-file + (plist-put consult--source-project-file + :items '(lambda () + (let* ((root (consult--project-root)) + (len (length root)) + (inv-root (propertize root 'invisible t))) + (mapcar (lambda (x) + (concat inv-root (substring x len))) + (split-string + (shell-command-to-string + (format "fd --color never -t f -0 . %s" root)) + "\0" t)))))) + + (defvar consult--source-perspective-buffer + `(:name "Perspective Buffer" + :narrow (?x . "Perspective") + :hidden t + :category buffer + :face consult-buffer + :history buffer-name-history + :state ,#'consult--buffer-state + :enabled ,(lambda () persp-mode) + :items + ,(lambda () + (consult--buffer-query :sort 'visibility + :predicate #'persp-is-current-buffer + :as #'buffer-name))) + "Perspective buffer candidate source for `consult-buffer'.") + (add-to-list 'consult-buffer-sources 'consult--source-perspective-buffer t) + + ;; Copy of consult--source-project-file to use with perspective narrowing (identical except for narrowing key) + (defvar consult--source-perspective-files + (plist-put (copy-sequence consult--source-project-file) :narrow '(?x "Project Files"))) + (add-to-list 'consult-buffer-sources 'consult--source-perspective-files t) + + ;; Versions of consult--source-project-buffer and consult--source-project-file for use by consult-project-buffer + ;; They allow narrowing with b and f (instead of p) + (defvar consult--project-source-project-buffer + (plist-put (plist-put (copy-sequence consult--source-project-buffer) + :hidden nil) + :narrow '(?b . "Project Buffer"))) + (defvar consult--project-source-project-file + (plist-put (plist-put (copy-sequence consult--source-project-file) + :hidden nil) + :narrow '(?f . "Project File"))) + + (defun consult-project-buffer () + (interactive) + (let ((consult-buffer-sources '(consult--project-source-project-buffer + consult--project-source-project-file))) + (consult-buffer))) (defun consult--orderless-regexp-compiler (input type) (setq input (orderless-pattern-compiler input)) @@ -267,38 +346,34 @@ (use-package consult-dir :ensure t :bind (("C-x C-d" . consult-dir) - :map vertico-map ;minibuffer-local-completion-map + :map vertico-map ("C-x C-d" . consult-dir) ("C-x C-j" . consult-dir-jump-file))) (use-package marginalia - :bind (("M-A" . marginalia-cycle) - :map minibuffer-local-map - ("M-A" . marginalia-cycle)) :init - (marginalia-mode) - :config - ;; For Projectile - (add-to-list 'marginalia-prompt-categories '("Switch to project" . file)) - (add-to-list 'marginalia-prompt-categories '("Find file" . project-file)) - (add-to-list 'marginalia-prompt-categories '("Recently visited files" . project-file)) - (add-to-list 'marginalia-prompt-categories '("Switch to buffer" . buffer)) - ;; For Crux - (add-to-list 'marginalia-prompt-categories '("Choose recent file" . file))) + (marginalia-mode)) (use-package embark :bind (("C-," . embark-act) - ;; CIDER will override M-. so have two bindings for this - ("M-." . embark-dwim) ("C-." . embark-dwim) ("C-c C-o" . embark-export) ("C-h b" . embark-bindings) - ("C-h B" . describe-bindings)) + ("C-h B" . describe-bindings) + (:map minibuffer-local-map + ("M-." . embark-preview))) :init - ;; Optionally replace the key help with a completing-read interface (setq prefix-help-command #'embark-prefix-help-command) :config + ;; (define-key minibuffer-local-map (kbd "M-.") #'embark-preview) + (defun embark-preview () + (interactive) + (unless (bound-and-true-p consult--preview-function) ;; Disable preview for Consult commands + (save-selected-window + (let ((embark-quit-after-action)) + (embark-default-action))))) + ;; Hide the mode line of the Embark live/completions buffers (add-to-list 'display-buffer-alist '("\\`\\*Embark Collect \\(Live\\|Completions\\)\\*" diff --git a/.emacs.d/lisp/init-navigation.el b/.emacs.d/lisp/init-navigation.el index e483637..082a64d 100644 --- a/.emacs.d/lisp/init-navigation.el +++ b/.emacs.d/lisp/init-navigation.el @@ -42,15 +42,9 @@ ;; TODO - which of these are useful? (use-package avy - :after key-chord :custom (avy-background t) (avy-style 'pre) - :config - (key-chord-define-global "LL" 'avy-goto-line) - (key-chord-define-global ",," 'avy-goto-char-in-line) - (key-chord-define-global "jj" 'avy-goto-word-1) - (key-chord-define-global "jk" 'avy-goto-char) :bind ("C-:" . avy-goto-char) ("C-'" . avy-goto-char-2) diff --git a/.emacs.d/lisp/init-project.el b/.emacs.d/lisp/init-project.el new file mode 100644 index 0000000..63aec7d --- /dev/null +++ b/.emacs.d/lisp/init-project.el @@ -0,0 +1,60 @@ +;;; init-project.el --- Project (and Perspective) Configuration File -*- lexical-binding: t -*- +;;; Commentary: +;;; Code: + +(use-package project + :ensure nil + :config + (defun project-recentf () + "Show a list of recently visited files in a project." + (interactive) + (if (boundp 'recentf-list) + (let* ((project-root (expand-file-name (project-root (project-current)))) + (project-recentf-files (mapcar + (lambda (f) (file-relative-name f project-root)) + (seq-filter (apply-partially 'string-prefix-p project-root) recentf-list)))) + (find-file (expand-file-name + (funcall project-read-file-name-function + "Find recent project files" + project-recentf-files nil 'file-name-history nil) + project-root))) + (message "recentf is not enabled"))) + + (add-to-list 'project-switch-commands '(?h "Recentf" project-recentf) t) + (add-to-list 'project-switch-commands '(?b "Consult Project Buffer" consult-project-buffer) t) + (add-to-list 'project-switch-commands '(?r "Consult Ripgrep" consult-ripgrep) t) + (add-to-list 'project-switch-commands '(?m "Magit" magit-status) t) + (add-to-list 'project-switch-commands '(?R "Replace Regexp" project-query-replace-regexp) t) + + ;; project-root and project-try-local copied/modified from https://github.com/karthink/project-x/blob/master/project-x.el + (cl-defmethod project-root ((project (head local))) + "Return root directory of current PROJECT." + (cdr project)) + (defun project-try-local (dir) + "Treat DIR as a project if it contains a .project file." + (if-let ((root (locate-dominating-file dir ".project"))) + (cons 'local root))) + ;; Add this hook last so so that vc takes precedence over local + (add-hook 'project-find-functions 'project-try-local 90) + :bind + ("C-x p P" . project-switch-project) + ("C-x f" . project-recentf)) + +(use-package perspective + :config (persp-mode) + (defun switch-project (proj) + "Switch to project or already open project perspective." + (interactive (list (project-prompt-project-dir))) + (let* ((persp-name (file-name-nondirectory (directory-file-name proj))) + (persp (gethash persp-name (perspectives-hash)))) + (unless (equal persp (persp-curr)) + ;; Create or switch to a perspective named after the project + (persp-switch persp-name) + ;; If the perspective did not exist, switch to the project + (when (not persp) + (project-switch-project proj))))) + :bind + ("C-x p p" . switch-project)) + +(provide 'init-project) +;;; init-project.el ends here diff --git a/.emacs.d/lisp/init-projectile.el b/.emacs.d/lisp/init-projectile.el deleted file mode 100644 index d314c8b..0000000 --- a/.emacs.d/lisp/init-projectile.el +++ /dev/null @@ -1,61 +0,0 @@ -;;; init-projectile.el --- Projectile Configuration File -*- lexical-binding: t -*- -;;; Commentary: -;;; Code: - -(defcustom projectile-default-dir "~/src" - "Starting directory when looking for new projects." - :group 'djm - :type 'directory) - -(defcustom projectile-switch-project-command 'projectile-persp-switch-project - "Projectile switch project command." - :group 'djm - :type 'function) - -(use-package projectile - :diminish - :after smartrep - :config - (projectile-mode t) - (define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map) - (def-projectile-commander-method ?b - "consult-buffer" - (progn - (setq unread-command-events (listify-key-sequence "p ")) - (consult-buffer))) - (def-projectile-commander-method ?B - "Switch to project buffer" - (projectile-switch-to-buffer)) - (def-projectile-commander-method ?r - "consult-ripgrep" - (consult-ripgrep)) - (def-projectile-commander-method ?p - "DWIM" - (cond ((> (length (projectile-project-buffer-names)) 4) (projectile-switch-to-buffer)) - ((> (length (projectile-recentf-files)) 0) (projectile-recentf)) - (t (projectile-find-file)))) - (defun projectile-open-new-project (project-root) - (interactive (list (read-directory-name "Select project directory: " (file-name-as-directory projectile-default-dir)))) - (projectile-add-known-project project-root) - (funcall projectile-switch-project-command project-root)) - (smartrep-define-key projectile-mode-map - "C-c p" '(("C-p" . projectile-previous-project-buffer) - ("C-n" . projectile-next-project-buffer))) - :bind-keymap ("C-c p" . projectile-command-map) - :bind - (:map projectile-mode-map - ("C-c p n" . projectile-open-new-project) - ("C-x f" . projectile-recentf)) - :custom - (projectile-switch-project-action 'projectile-commander) - (projectile-cache-file (expand-file-name "projectile.cache" save-dir))) - -(use-package perspective - :init (persp-mode) - :bind ("C-x C-b" . persp-ibuffer) - :custom (persp-modestring-short t)) - -(use-package persp-projectile) - -(provide 'init-projectile) -;;; init-projectile.el ends here diff --git a/.emacs.d/lisp/init-search.el b/.emacs.d/lisp/init-search.el index c9a8305..f9c8c31 100644 --- a/.emacs.d/lisp/init-search.el +++ b/.emacs.d/lisp/init-search.el @@ -8,9 +8,8 @@ (search-whitespace-regexp ".*\\b") (isearch-lax-whitespace t) (isearch-allow-scroll t) - ;; TODO - ;; (isearch-yank-on-move 'shift) - (isearch-yank-on-move t) + (isearch-yank-on-move 'shift) + (isearch-lazy-count t) :bind-keymap ("C-c s" . search-map) ;; M-s clashes with paredit/smartparens bindings :bind ("C-*" . isearch-forward-symbol-at-point) diff --git a/.emacs.d/lisp/init-shell.el b/.emacs.d/lisp/init-shell.el index 84f94d5..651ad61 100644 --- a/.emacs.d/lisp/init-shell.el +++ b/.emacs.d/lisp/init-shell.el @@ -16,16 +16,13 @@ :defer t :hook (eshell-mode . (lambda () (require 'eshell-z)))) -(use-package esh-autosuggest - :hook (eshell-mode . esh-autosuggest-mode)) - (use-package eshell-syntax-highlighting :after esh-mode :config (eshell-syntax-highlighting-global-mode +1)) (use-package xterm-color - :after eshell + :after esh-mode :hook (eshell-before-prompt . (lambda () (setq xterm-color-preserve-properties t))) @@ -36,6 +33,7 @@ (use-package multi-vterm :bind (("C-c t" . multi-vterm-next) + ("C-x p t" . multi-vterm-project) ("C-c C-M-t" . multi-vterm) (:map vterm-mode-map ("M-[" . multi-vterm-prev) diff --git a/.emacs.d/lisp/init-ui.el b/.emacs.d/lisp/init-ui.el index f32e50b..c11bed4 100644 --- a/.emacs.d/lisp/init-ui.el +++ b/.emacs.d/lisp/init-ui.el @@ -92,11 +92,9 @@ :diminish :config (which-key-mode +1)) -;; Other key-chords defined with in the relevant use-package calls (use-package key-chord :config - (key-chord-mode +1) - (key-chord-define-global "xx" 'execute-extended-command)) + (key-chord-mode +1)) (use-package rainbow-delimiters :config