Get rid of lambdas and scope defuns

This commit is contained in:
Wojciech Kozlowski 2022-04-11 17:15:26 +02:00
parent d46069050c
commit ac288e5ad0

113
config.el
View File

@ -102,12 +102,14 @@
(advice-remove 'newline-and-indent (advice-remove 'newline-and-indent
#'+default--newline-indent-and-continue-comments-a) #'+default--newline-indent-and-continue-comments-a)
;; Add some extra whitespace highlights to doom's opinion. ;; Doom already uses whitespace-mode to highlight unexpected indentation. Add
(advice-add 'doom-highlight-non-default-indentation-h ;; some extras by defining an advice function.
:after (defadvice! +doom-highlight-unwanted-space-h nil
(lambda () (when (bound-and-true-p whitespace-mode) "Add some extra whitespace highlights to doom's opinion"
(appendq! whitespace-style '(trailing lines-tail empty)) :after #'doom-highlight-non-default-indentation-h
(whitespace-mode +1)))) (when (bound-and-true-p whitespace-mode)
(appendq! whitespace-style '(trailing lines-tail empty))
(whitespace-mode +1)))
;; I actually like it when Emacs recenters the screen while scrolling. This may ;; I actually like it when Emacs recenters the screen while scrolling. This may
;; be an issue in large files. When that becomes an issue add an exception here. ;; be an issue in large files. When that becomes an issue add an exception here.
@ -119,16 +121,15 @@
;; Fix git-gutter advice for magit. ;; Fix git-gutter advice for magit.
(after! (:all git-gutter magit) (after! (:all git-gutter magit)
;; Define a function that updates all visible buffers. ;; Update all visible buffers when (un)staging in the magit buffer.
(defun +vc-gutter-update-visible-buffers-h (&rest _) (defadvice! +vc-gutter-update-visible-buffers-h (&rest _)
"Update vc-gutter in all visible buffers."
:after #'magit-stage
:after #'magit-unstage
(save-excursion (save-excursion
(dolist (buffer (doom-visible-buffers) nil) (dolist (buffer (doom-visible-buffers) nil)
(with-current-buffer buffer (with-current-buffer buffer
(+vc-gutter-update-h))))) (+vc-gutter-update-h))))))
;; And add this as new advice to the magit functions.
(advice-add 'magit-stage :after #'+vc-gutter-update-visible-buffers-h)
(advice-add 'magit-unstage :after #'+vc-gutter-update-visible-buffers-h))
;; Disable hl-line-mode everywhere. ;; Disable hl-line-mode everywhere.
(after! hl-line (setq global-hl-line-modes nil)) (after! hl-line (setq global-hl-line-modes nil))
@ -163,7 +164,8 @@
;; The only thing I actually missed from helm. ;; The only thing I actually missed from helm.
(map! (:when (featurep! :completion vertico) (map! (:when (featurep! :completion vertico)
:map vertico-map :map vertico-map
"C-l" (lambda () "C-l" (defun +vertico-directory-delete-one-word ()
"Delete one directory or word before point."
(interactive) (interactive)
(vertico-directory-delete-word 1)))) (vertico-directory-delete-word 1))))
@ -191,20 +193,19 @@
;; A nicer interface for ripgrep. Note that since doom required rg we don't ;; A nicer interface for ripgrep. Note that since doom required rg we don't
;; consider the case if it's not installed. ;; consider the case if it's not installed.
(use-package! deadgrep (use-package! deadgrep
:bind (("C-x C-g" . deadgrep))
:init :init
(setq deadgrep-project-root-function (setq deadgrep-project-root-function
(lambda () (defun +deadgrep-project-root ()
"Provide a base directory for deadgrep."
(read-directory-name "Base directory: " nil default-directory t))) (read-directory-name "Base directory: " nil default-directory t)))
:bind
(("C-x C-g" . deadgrep))
(:map deadgrep-mode-map
("C-o" . +deadgrep-open-result-other-window)
("<RET>" . deadgrep-visit-result-other-window))
:config :config
(defun +deadgrep-open-result-other-window () (map! (:map deadgrep-mode-map
"Open the result in other window without changing to it." "C-o" (defun +deadgrep-open-result-other-window ()
(interactive) "Open the result in other window without changing to it."
(save-selected-window (deadgrep-visit-result-other-window)))) (interactive)
(save-selected-window (deadgrep-visit-result-other-window)))
"<RET>" #'deadgrep-visit-result-other-window)))
;; Duplicate things. ;; Duplicate things.
(use-package! duplicate-thing (use-package! duplicate-thing
@ -239,8 +240,10 @@
;; Highlight lines that are too long in whitespace mode. We set this with a hook ;; Highlight lines that are too long in whitespace mode. We set this with a hook
;; after local variables as fill-column is often set through dir-locals. ;; after local variables as fill-column is often set through dir-locals.
(add-hook 'hack-local-variables-hook (add-hook! 'hack-local-variables-hook
(lambda () (setq-local whitespace-line-column fill-column))) (defun +update-whitespace-line-column ()
"Change `whitespace-line-column' to that of `fill-column'."
(setq-local whitespace-line-column fill-column)))
;; CamelCase as separate words. ;; CamelCase as separate words.
(global-subword-mode +1) (global-subword-mode +1)
@ -254,43 +257,41 @@
(defalias #'end-of-visual-line #'end-of-line) (defalias #'end-of-visual-line #'end-of-line)
(defalias #'beginning-of-visual-line #'beginning-of-line) (defalias #'beginning-of-visual-line #'beginning-of-line)
(defun +indent-region-or-buffer ()
"Indent a region if selected, otherwise the whole buffer."
(interactive)
(if (region-active-p)
(indent-region (region-beginning) (region-end))
(indent-region (point-min) (point-max))))
(defun +unfill-paragraph (&optional region)
"Takes a multi-line paragraph and makes it into a single line of text."
(interactive (progn (barf-if-buffer-read-only) '(t)))
(let ((fill-column (point-max))
;; This would override `fill-column' if it's an integer.
(emacs-lisp-docstring-fill-column t))
(fill-paragraph nil region)))
;; ----------------------------------------------------------------------------- ;; -----------------------------------------------------------------------------
;; Global keybindings. ;; Global keybindings.
;; ----------------------------------------------------------------------------- ;; -----------------------------------------------------------------------------
(map! (map!
;; For functions defined above. "C-M-\\" (defun indent-region-or-buffer ()
"M-Q" #'+unfill-paragraph "Indent a region if selected, otherwise the whole buffer."
"C-M-\\" #'+indent-region-or-buffer (interactive)
(if (region-active-p)
(indent-region (region-beginning) (region-end))
(indent-region (point-min) (point-max))))
"C-x k" #'kill-current-buffer
"C-<" (defun scroll-down-one ()
"Scroll text (but not the point) of selected window downward one line."
(interactive)
(let ((scroll-preserve-screen-position nil)) (scroll-down 1)))
"C->" (defun scroll-up-one ()
"Scroll text (but not the point) of selected window upward one line."
(interactive)
(let ((scroll-preserve-screen-position nil)) (scroll-up 1)))
"M-Q" (defun unfill-paragraph (&optional region)
"Takes a multi-line paragraph and makes it into a single line of text."
(interactive (progn (barf-if-buffer-read-only) '(t)))
(let ((fill-column (point-max))
;; This would override `fill-column' if it's an integer.
(emacs-lisp-docstring-fill-column t))
(fill-paragraph nil region)))
;; Create binding before dired is loaded. ;; Create binding before dired is loaded.
"C-x C-j" #'dired-jump "C-x C-j" #'dired-jump
;; More convenient window switching. ;; More convenient window switching.
"M-o" #'other-window "M-o" #'other-window
"C-x o" #'other-popup "C-x o" #'other-popup)
;; Kill current buffer without prompting.
:desc "kill-buffer"
"C-x k" (lambda ()
(interactive)
(let (kill-buffer-query-functions) (kill-buffer)))
;; Scroll up/down, but keep point in place.
"C-<" (lambda()
(interactive)
(let ((scroll-preserve-screen-position nil)) (scroll-down 1)))
"C->" (lambda()
(interactive)
(let ((scroll-preserve-screen-position nil)) (scroll-up 1))))