aboutsummaryrefslogtreecommitdiff
path: root/modules/prog-general.el
diff options
context:
space:
mode:
Diffstat (limited to 'modules/prog-general.el')
-rw-r--r--modules/prog-general.el76
1 files changed, 41 insertions, 35 deletions
diff --git a/modules/prog-general.el b/modules/prog-general.el
index 8b4dedda4..968032831 100644
--- a/modules/prog-general.el
+++ b/modules/prog-general.el
@@ -64,20 +64,36 @@
(defvar treesit-auto-recipe-list)
;; Forward declarations for functions defined later in this file
-(declare-function cj/find-project-root-file "prog-general")
(declare-function cj/project-switch-actions "prog-general")
(declare-function cj/deadgrep--initial-term "prog-general")
+
+(defun cj/find-project-root-file (regexp)
+ "Return first file in the current Projectile project root matching REGEXP.
+
+Match is done against (downcase file) for case-insensitivity.
+REGEXP must be a string or an rx form."
+ (when-let ((root (projectile-project-root)))
+ (seq-find (lambda (file)
+ (string-match-p (if (stringp regexp)
+ regexp
+ (rx-to-string regexp))
+ (downcase file)))
+ (directory-files root))))
(declare-function cj/highlight-indent-guides-disable-in-non-prog-modes "prog-general")
;; --------------------- General Programming Mode Settings ---------------------
;; keybindings, minor-modes, and prog-mode settings
+;; Set the line-number type and width before any prog buffer enables
+;; display-line-numbers-mode. Setting them inside the hook ran after the mode
+;; turned on, so the first prog buffer of a session got absolute numbers.
+(setq display-line-numbers-type 'relative) ;; numbers relative to point
+(setq-default display-line-numbers-width 3) ;; 3 chars reserved for numbers
+
(defun cj/general-prog-settings ()
"Keybindings, minor modes, and settings for programming mode."
(interactive)
(display-line-numbers-mode) ;; show line numbers
- (setq display-line-numbers-type 'relative) ;; display numbers relative to 'the point'
- (setq-default display-line-numbers-width 3) ;; 3 characters reserved for line numbers
(turn-on-visual-line-mode) ;; word-wrapping
(auto-fill-mode) ;; auto wrap at the fill column set
(local-set-key (kbd "M-;") 'comment-dwim) ;; comment/uncomment region as appropriate
@@ -173,19 +189,6 @@ reuses the current window otherwise, matching `cj/open-project-root-todo'."
:config
(require 'seq)
- (defun cj/find-project-root-file (regexp)
- "Return first file in the current Projectile project root matching REGEXP.
-
-Match is done against (downcase file) for case-insensitivity.
-REGEXP must be a string or an rx form."
- (when-let ((root (projectile-project-root)))
- (seq-find (lambda (file)
- (string-match-p (if (stringp regexp)
- regexp
- (rx-to-string regexp))
- (downcase file)))
- (directory-files root))))
-
(defun cj/open-project-root-todo ()
"Open todo.org in the current Projectile project root.
@@ -229,6 +232,23 @@ If no such file exists there, display a message."
;; ---------------------------------- Ripgrep ----------------------------------
+(declare-function deadgrep "deadgrep")
+
+(defun cj/deadgrep--initial-term ()
+ "Return the region text or the symbol at point, to seed a Deadgrep search."
+ (cond
+ ((use-region-p)
+ (buffer-substring-no-properties (region-beginning) (region-end)))
+ (t (thing-at-point 'symbol t))))
+
+(defun cj/--deadgrep-run (root &optional term)
+ "Run Deadgrep for TERM under directory ROOT.
+ROOT is normalized to a directory name; TERM defaults to a minibuffer read
+seeded by `cj/deadgrep--initial-term'. Shared tail of the deadgrep commands."
+ (let ((root (file-name-as-directory (expand-file-name root)))
+ (term (or term (read-from-minibuffer "Search: " (cj/deadgrep--initial-term)))))
+ (deadgrep term root)))
+
(use-package deadgrep
:after projectile
:bind
@@ -239,12 +259,6 @@ If no such file exists there, display a message."
:config
(require 'thingatpt)
- (defun cj/deadgrep--initial-term ()
- (cond
- ((use-region-p)
- (buffer-substring-no-properties (region-beginning) (region-end)))
- (t (thing-at-point 'symbol t))))
-
(defun cj/deadgrep-here (&optional term)
"Search with Deadgrep in the most relevant directory at point."
(interactive)
@@ -261,17 +275,14 @@ If no such file exists there, display a message."
(buffer-file-name
(file-name-directory (file-truename buffer-file-name)))
(t default-directory)))
- (root (file-name-as-directory (expand-file-name root)))
- (term (or term (read-from-minibuffer "Search: " (cj/deadgrep--initial-term)))))
- (deadgrep term root)))
+ )
+ (cj/--deadgrep-run root term)))
(defun cj/deadgrep-in-dir (&optional dir term)
"Prompt for a directory, then search there with Deadgrep."
(interactive)
- (let* ((dir (or dir (read-directory-name "Search in directory: " default-directory nil t)))
- (dir (file-name-as-directory (expand-file-name dir)))
- (term (or term (read-from-minibuffer "Search: " (cj/deadgrep--initial-term)))))
- (deadgrep term dir))))
+ (let ((dir (or dir (read-directory-name "Search in directory: " default-directory nil t))))
+ (cj/--deadgrep-run dir term))))
(with-eval-after-load 'dired
(keymap-set dired-mode-map "G" #'cj/deadgrep-here))
@@ -336,14 +347,9 @@ defer to `electric-pair-default-inhibit' for any other CHAR."
(use-package highlight-indent-guides
:hook (prog-mode . cj/highlight-indent-guides-enable)
:config
- ;; Disable auto face coloring to use explicit faces for better visibility across themes
+ ;; Disable auto face coloring; the guide faces are left to the theme
(setq highlight-indent-guides-auto-enabled nil)
- ;; Set explicit face backgrounds and foreground for the indentation guides
- (set-face-background 'highlight-indent-guides-odd-face "darkgray")
- (set-face-background 'highlight-indent-guides-even-face "darkgray")
- (set-face-foreground 'highlight-indent-guides-character-face "dimgray")
-
(defun cj/highlight-indent-guides-enable ()
"Enable highlight-indent-guides with preferred settings for programming modes."
(setq-local highlight-indent-guides-method 'bitmap)