2019-04-21 19:59:44 -04:00
|
|
|
;;; editor/evil/autoload/advice.el -*- lexical-binding: t; -*-
|
2018-09-07 22:02:41 -04:00
|
|
|
|
|
|
|
;;;###autoload
|
:boom: revise advice naming convention (1/2)
This is first of three big naming convention updates that have been a
long time coming. With 2.1 on the horizon, all the breaking updates will
batched together in preparation for the long haul.
In this commit, we do away with the asterix to communicate that a
function is an advice function, and we replace it with the '-a' suffix.
e.g.
doom*shut-up -> doom-shut-up-a
doom*recenter -> doom-recenter-a
+evil*static-reindent -> +evil--static-reindent-a
The rationale behind this change is:
1. Elisp's own formatting/indenting tools would occasionally struggle
with | and * (particularly pp and cl-prettyprint). They have no
problem with / and :, fortunately.
2. External syntax highlighters (like pygmentize, discord markdown or
github markdown) struggle with it, sometimes refusing to highlight
code beyond these symbols.
3. * and | are less expressive than - and -- in communicating the
intended visibility, versatility and stability of a function.
4. It complicated the regexps we must use to search for them.
5. They were arbitrary and over-complicated to begin with, decided
on haphazardly way back when Doom was simply "my private config".
Anyhow, like how predicate functions have the -p suffix, we'll adopt the
-a suffix for advice functions, -h for hook functions and -fn for
variable functions.
Other noteable changes:
- Replaces advice-{add,remove}! macro with new def-advice!
macro. The old pair weren't as useful. The new def-advice! saves on a
lot of space.
- Removed "stage" assertions to make sure you were using the right
macros in the right place. Turned out to not be necessary, we'll
employ better checks later.
2019-07-18 15:42:52 +02:00
|
|
|
(defun +evil-escape-a (&rest _)
|
|
|
|
"Call `doom/escape' if `evil-force-normal-state' is called interactively."
|
|
|
|
(when (called-interactively-p 'any)
|
|
|
|
(call-interactively #'doom/escape)))
|
2018-09-07 22:02:41 -04:00
|
|
|
|
|
|
|
;;;###autoload
|
2020-04-26 04:12:33 -04:00
|
|
|
(defun +evil-replace-filename-modifiers-a (file-name)
|
2018-09-07 22:02:41 -04:00
|
|
|
"Take a path and resolve any vim-like filename modifiers in it. This adds
|
|
|
|
support for most vim file modifiers, as well as:
|
|
|
|
|
|
|
|
%:P Resolves to `doom-project-root'.
|
|
|
|
|
|
|
|
See http://vimdoc.sourceforge.net/htmldoc/cmdline.html#filename-modifiers for
|
|
|
|
more information on modifiers."
|
2020-04-26 04:12:33 -04:00
|
|
|
(let ((origin-buffer (current-buffer))
|
|
|
|
case-fold-search)
|
2020-02-20 00:51:55 -05:00
|
|
|
(with-temp-buffer
|
2020-04-26 04:12:33 -04:00
|
|
|
(let ((buffer-file-name (buffer-file-name origin-buffer)))
|
|
|
|
(save-excursion (insert file-name))
|
|
|
|
(while (re-search-forward "\\(^\\|[^\\\\]\\)\\(\\([%#]\\)\\(:\\([PphtreS~.]\\|g?s\\)\\)*\\)" nil t)
|
|
|
|
(if (null buffer-file-name)
|
|
|
|
(replace-match (match-string 1) t t nil 2)
|
|
|
|
(let ((beg (match-beginning 2))
|
|
|
|
(end (match-end 3))
|
|
|
|
(path (pcase (match-string 3)
|
|
|
|
("%" (file-relative-name buffer-file-name default-directory))
|
|
|
|
("#" (and (other-buffer origin-buffer)
|
|
|
|
(buffer-file-name (other-buffer origin-buffer)))))))
|
|
|
|
(save-match-data
|
|
|
|
(goto-char beg)
|
|
|
|
(while (re-search-forward ":\\([PphtreS~.]\\|g?s\\)" (+ (point) 3) t)
|
|
|
|
(let* ((modifier (match-string 1))
|
|
|
|
(global (string-prefix-p "gs" modifier)))
|
|
|
|
(when global
|
|
|
|
(setq modifier (substring modifier 1)))
|
|
|
|
(setq end (match-end 1)
|
|
|
|
path
|
|
|
|
(pcase (and path (substring modifier 0 1))
|
|
|
|
(`nil "")
|
|
|
|
("p" (expand-file-name path))
|
|
|
|
("~" (concat "~/" (file-relative-name path "~")))
|
|
|
|
("." (file-relative-name path))
|
|
|
|
("t" (file-name-nondirectory (directory-file-name path)))
|
|
|
|
("r" (file-name-sans-extension path))
|
|
|
|
("e" (file-name-extension path))
|
|
|
|
("S" (shell-quote-argument path))
|
|
|
|
("h"
|
|
|
|
(let ((parent (file-name-directory (expand-file-name path))))
|
|
|
|
(unless (file-equal-p path parent)
|
|
|
|
(if (file-name-absolute-p path)
|
|
|
|
(directory-file-name parent)
|
|
|
|
(file-relative-name parent)))))
|
|
|
|
("s"
|
|
|
|
(if (featurep 'evil)
|
|
|
|
(when-let (args (evil-delimited-arguments (substring modifier 1) 2))
|
|
|
|
(let ((pattern (evil-transform-vim-style-regexp (car args)))
|
|
|
|
(replace (cadr args)))
|
|
|
|
(replace-regexp-in-string
|
|
|
|
(if global pattern (concat "\\(" pattern "\\).*\\'"))
|
|
|
|
(evil-transform-vim-style-regexp replace) path t t
|
|
|
|
(unless global 1))))
|
|
|
|
path))
|
|
|
|
("P"
|
|
|
|
(let ((project-root (doom-project-root (file-name-directory (expand-file-name path)))))
|
|
|
|
(unless project-root
|
|
|
|
(user-error "Not in a project"))
|
|
|
|
(abbreviate-file-name project-root)))))
|
|
|
|
;; strip trailing slash, if applicable
|
|
|
|
(or (string-empty-p path)
|
|
|
|
(not (equal (substring path -1) "/"))
|
|
|
|
(setq path (substring path 0 -1))))))
|
|
|
|
(replace-match path t t nil 2))))
|
|
|
|
(replace-regexp-in-string "\\\\\\([#%]\\)" "\\1" (buffer-string) t)))))
|
2018-09-07 22:02:41 -04:00
|
|
|
|
:boom: revise advice naming convention (1/2)
This is first of three big naming convention updates that have been a
long time coming. With 2.1 on the horizon, all the breaking updates will
batched together in preparation for the long haul.
In this commit, we do away with the asterix to communicate that a
function is an advice function, and we replace it with the '-a' suffix.
e.g.
doom*shut-up -> doom-shut-up-a
doom*recenter -> doom-recenter-a
+evil*static-reindent -> +evil--static-reindent-a
The rationale behind this change is:
1. Elisp's own formatting/indenting tools would occasionally struggle
with | and * (particularly pp and cl-prettyprint). They have no
problem with / and :, fortunately.
2. External syntax highlighters (like pygmentize, discord markdown or
github markdown) struggle with it, sometimes refusing to highlight
code beyond these symbols.
3. * and | are less expressive than - and -- in communicating the
intended visibility, versatility and stability of a function.
4. It complicated the regexps we must use to search for them.
5. They were arbitrary and over-complicated to begin with, decided
on haphazardly way back when Doom was simply "my private config".
Anyhow, like how predicate functions have the -p suffix, we'll adopt the
-a suffix for advice functions, -h for hook functions and -fn for
variable functions.
Other noteable changes:
- Replaces advice-{add,remove}! macro with new def-advice!
macro. The old pair weren't as useful. The new def-advice! saves on a
lot of space.
- Removed "stage" assertions to make sure you were using the right
macros in the right place. Turned out to not be necessary, we'll
employ better checks later.
2019-07-18 15:42:52 +02:00
|
|
|
(defun +evil--insert-newline (&optional above _noextranewline)
|
|
|
|
(let ((pos (save-excursion (beginning-of-line-text) (point)))
|
|
|
|
comment-auto-fill-only-comments)
|
|
|
|
(require 'smartparens)
|
|
|
|
(evil-narrow-to-field
|
|
|
|
(if above
|
|
|
|
(if (save-excursion (nth 4 (sp--syntax-ppss pos)))
|
|
|
|
(evil-save-goal-column
|
|
|
|
(setq evil-auto-indent nil)
|
|
|
|
(goto-char pos)
|
|
|
|
(let ((ws (abs (skip-chars-backward " \t"))))
|
|
|
|
;; FIXME oh god why
|
|
|
|
(save-excursion
|
|
|
|
(if comment-line-break-function
|
2019-11-15 19:15:23 -05:00
|
|
|
(funcall comment-line-break-function nil)
|
:boom: revise advice naming convention (1/2)
This is first of three big naming convention updates that have been a
long time coming. With 2.1 on the horizon, all the breaking updates will
batched together in preparation for the long haul.
In this commit, we do away with the asterix to communicate that a
function is an advice function, and we replace it with the '-a' suffix.
e.g.
doom*shut-up -> doom-shut-up-a
doom*recenter -> doom-recenter-a
+evil*static-reindent -> +evil--static-reindent-a
The rationale behind this change is:
1. Elisp's own formatting/indenting tools would occasionally struggle
with | and * (particularly pp and cl-prettyprint). They have no
problem with / and :, fortunately.
2. External syntax highlighters (like pygmentize, discord markdown or
github markdown) struggle with it, sometimes refusing to highlight
code beyond these symbols.
3. * and | are less expressive than - and -- in communicating the
intended visibility, versatility and stability of a function.
4. It complicated the regexps we must use to search for them.
5. They were arbitrary and over-complicated to begin with, decided
on haphazardly way back when Doom was simply "my private config".
Anyhow, like how predicate functions have the -p suffix, we'll adopt the
-a suffix for advice functions, -h for hook functions and -fn for
variable functions.
Other noteable changes:
- Replaces advice-{add,remove}! macro with new def-advice!
macro. The old pair weren't as useful. The new def-advice! saves on a
lot of space.
- Removed "stage" assertions to make sure you were using the right
macros in the right place. Turned out to not be necessary, we'll
employ better checks later.
2019-07-18 15:42:52 +02:00
|
|
|
(comment-indent-new-line))
|
|
|
|
(when (and (derived-mode-p 'c-mode 'c++-mode 'objc-mode 'java-mode 'js2-mode)
|
|
|
|
(eq (char-after) ?/))
|
|
|
|
(insert "*"))
|
|
|
|
(insert
|
|
|
|
(make-string (max 0 (+ ws (skip-chars-backward " \t")))
|
|
|
|
32)))
|
|
|
|
(insert (make-string (max 1 ws) 32))))
|
|
|
|
(evil-move-beginning-of-line)
|
|
|
|
(insert (if use-hard-newlines hard-newline "\n"))
|
|
|
|
(forward-line -1)
|
|
|
|
(back-to-indentation))
|
|
|
|
(evil-move-end-of-line)
|
|
|
|
(cond ((sp-point-in-comment pos)
|
|
|
|
(setq evil-auto-indent nil)
|
|
|
|
(if comment-line-break-function
|
|
|
|
(funcall comment-line-break-function)
|
|
|
|
(comment-indent-new-line)))
|
|
|
|
;; TODO Find a better way to do this
|
|
|
|
((and (eq major-mode 'haskell-mode)
|
|
|
|
(fboundp 'haskell-indentation-newline-and-indent))
|
|
|
|
(setq evil-auto-indent nil)
|
|
|
|
(haskell-indentation-newline-and-indent))
|
|
|
|
(t
|
|
|
|
(insert (if use-hard-newlines hard-newline "\n"))
|
|
|
|
(back-to-indentation)))))))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +evil--insert-newline-below-and-respect-comments-a (orig-fn count)
|
|
|
|
(if (or (not +evil-want-o/O-to-continue-comments)
|
|
|
|
(not (eq this-command 'evil-open-below))
|
|
|
|
(evil-insert-state-p))
|
|
|
|
(funcall orig-fn count)
|
2020-04-29 21:08:17 -04:00
|
|
|
(letf! (defun evil-insert-newline-below () (+evil--insert-newline))
|
:boom: revise advice naming convention (1/2)
This is first of three big naming convention updates that have been a
long time coming. With 2.1 on the horizon, all the breaking updates will
batched together in preparation for the long haul.
In this commit, we do away with the asterix to communicate that a
function is an advice function, and we replace it with the '-a' suffix.
e.g.
doom*shut-up -> doom-shut-up-a
doom*recenter -> doom-recenter-a
+evil*static-reindent -> +evil--static-reindent-a
The rationale behind this change is:
1. Elisp's own formatting/indenting tools would occasionally struggle
with | and * (particularly pp and cl-prettyprint). They have no
problem with / and :, fortunately.
2. External syntax highlighters (like pygmentize, discord markdown or
github markdown) struggle with it, sometimes refusing to highlight
code beyond these symbols.
3. * and | are less expressive than - and -- in communicating the
intended visibility, versatility and stability of a function.
4. It complicated the regexps we must use to search for them.
5. They were arbitrary and over-complicated to begin with, decided
on haphazardly way back when Doom was simply "my private config".
Anyhow, like how predicate functions have the -p suffix, we'll adopt the
-a suffix for advice functions, -h for hook functions and -fn for
variable functions.
Other noteable changes:
- Replaces advice-{add,remove}! macro with new def-advice!
macro. The old pair weren't as useful. The new def-advice! saves on a
lot of space.
- Removed "stage" assertions to make sure you were using the right
macros in the right place. Turned out to not be necessary, we'll
employ better checks later.
2019-07-18 15:42:52 +02:00
|
|
|
(let ((evil-auto-indent evil-auto-indent))
|
|
|
|
(funcall orig-fn count)))))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +evil--insert-newline-above-and-respect-comments-a (orig-fn count)
|
|
|
|
(if (or (not +evil-want-o/O-to-continue-comments)
|
|
|
|
(not (eq this-command 'evil-open-above))
|
|
|
|
(evil-insert-state-p))
|
|
|
|
(funcall orig-fn count)
|
2020-04-29 21:08:17 -04:00
|
|
|
(letf! (defun evil-insert-newline-above () (+evil--insert-newline 'above))
|
:boom: revise advice naming convention (1/2)
This is first of three big naming convention updates that have been a
long time coming. With 2.1 on the horizon, all the breaking updates will
batched together in preparation for the long haul.
In this commit, we do away with the asterix to communicate that a
function is an advice function, and we replace it with the '-a' suffix.
e.g.
doom*shut-up -> doom-shut-up-a
doom*recenter -> doom-recenter-a
+evil*static-reindent -> +evil--static-reindent-a
The rationale behind this change is:
1. Elisp's own formatting/indenting tools would occasionally struggle
with | and * (particularly pp and cl-prettyprint). They have no
problem with / and :, fortunately.
2. External syntax highlighters (like pygmentize, discord markdown or
github markdown) struggle with it, sometimes refusing to highlight
code beyond these symbols.
3. * and | are less expressive than - and -- in communicating the
intended visibility, versatility and stability of a function.
4. It complicated the regexps we must use to search for them.
5. They were arbitrary and over-complicated to begin with, decided
on haphazardly way back when Doom was simply "my private config".
Anyhow, like how predicate functions have the -p suffix, we'll adopt the
-a suffix for advice functions, -h for hook functions and -fn for
variable functions.
Other noteable changes:
- Replaces advice-{add,remove}! macro with new def-advice!
macro. The old pair weren't as useful. The new def-advice! saves on a
lot of space.
- Removed "stage" assertions to make sure you were using the right
macros in the right place. Turned out to not be necessary, we'll
employ better checks later.
2019-07-18 15:42:52 +02:00
|
|
|
(let ((evil-auto-indent evil-auto-indent))
|
|
|
|
(funcall orig-fn count)))))
|
|
|
|
|
|
|
|
;;;###autoload (autoload '+evil-window-split-a "editor/evil/autoload/advice" nil t)
|
|
|
|
(evil-define-command +evil-window-split-a (&optional count file)
|
2019-10-29 18:27:19 -04:00
|
|
|
"Same as `evil-window-split', but correctly updates the window history."
|
2018-09-07 22:02:41 -04:00
|
|
|
:repeat nil
|
|
|
|
(interactive "P<f>")
|
2019-10-29 18:27:19 -04:00
|
|
|
;; HACK This ping-ponging between the destination and source windows is to
|
|
|
|
;; update the window focus history, so that, if you close either split
|
|
|
|
;; afterwards you won't be sent to some random window.
|
2019-11-23 00:52:36 -05:00
|
|
|
(let ((doom-inhibit-switch-window-hooks t)
|
|
|
|
(origwin (selected-window)))
|
|
|
|
(select-window (split-window origwin count 'below))
|
2019-10-29 18:27:19 -04:00
|
|
|
(unless evil-split-window-below
|
|
|
|
(select-window origwin))
|
|
|
|
(run-hooks 'doom-switch-window-hook))
|
2018-09-07 22:02:41 -04:00
|
|
|
(recenter)
|
|
|
|
(when (and (not count) evil-auto-balance-windows)
|
|
|
|
(balance-windows (window-parent)))
|
|
|
|
(if file (evil-edit file)))
|
|
|
|
|
:boom: revise advice naming convention (1/2)
This is first of three big naming convention updates that have been a
long time coming. With 2.1 on the horizon, all the breaking updates will
batched together in preparation for the long haul.
In this commit, we do away with the asterix to communicate that a
function is an advice function, and we replace it with the '-a' suffix.
e.g.
doom*shut-up -> doom-shut-up-a
doom*recenter -> doom-recenter-a
+evil*static-reindent -> +evil--static-reindent-a
The rationale behind this change is:
1. Elisp's own formatting/indenting tools would occasionally struggle
with | and * (particularly pp and cl-prettyprint). They have no
problem with / and :, fortunately.
2. External syntax highlighters (like pygmentize, discord markdown or
github markdown) struggle with it, sometimes refusing to highlight
code beyond these symbols.
3. * and | are less expressive than - and -- in communicating the
intended visibility, versatility and stability of a function.
4. It complicated the regexps we must use to search for them.
5. They were arbitrary and over-complicated to begin with, decided
on haphazardly way back when Doom was simply "my private config".
Anyhow, like how predicate functions have the -p suffix, we'll adopt the
-a suffix for advice functions, -h for hook functions and -fn for
variable functions.
Other noteable changes:
- Replaces advice-{add,remove}! macro with new def-advice!
macro. The old pair weren't as useful. The new def-advice! saves on a
lot of space.
- Removed "stage" assertions to make sure you were using the right
macros in the right place. Turned out to not be necessary, we'll
employ better checks later.
2019-07-18 15:42:52 +02:00
|
|
|
;;;###autoload (autoload '+evil-window-vsplit-a "editor/evil/autoload/advice" nil t)
|
|
|
|
(evil-define-command +evil-window-vsplit-a (&optional count file)
|
2019-10-29 18:27:19 -04:00
|
|
|
"Same as `evil-window-split', but correctly updates the window history."
|
2018-09-07 22:02:41 -04:00
|
|
|
:repeat nil
|
|
|
|
(interactive "P<f>")
|
2019-10-29 18:27:19 -04:00
|
|
|
;; HACK This ping-ponging between the destination and source windows is to
|
|
|
|
;; update the window focus history, so that, if you close either split
|
|
|
|
;; afterwards you won't be sent to some random window.
|
2019-11-23 00:52:36 -05:00
|
|
|
(let ((doom-inhibit-switch-window-hooks t)
|
|
|
|
(origwin (selected-window)))
|
|
|
|
(select-window (split-window origwin count 'right))
|
2019-10-29 18:27:19 -04:00
|
|
|
(unless evil-vsplit-window-right
|
|
|
|
(select-window origwin))
|
|
|
|
(run-hooks 'doom-switch-window-hook))
|
|
|
|
(run-hooks)
|
2018-09-07 22:02:41 -04:00
|
|
|
(recenter)
|
|
|
|
(when (and (not count) evil-auto-balance-windows)
|
|
|
|
(balance-windows (window-parent)))
|
|
|
|
(if file (evil-edit file)))
|
|
|
|
|
2019-03-04 20:42:04 -05:00
|
|
|
;;;###autoload
|
2019-07-18 15:27:20 +02:00
|
|
|
(defun +evil--fix-dabbrev-in-minibuffer-h ()
|
2019-03-04 20:42:04 -05:00
|
|
|
"Make `try-expand-dabbrev' from `hippie-expand' work in minibuffer. See
|
|
|
|
`he-dabbrev-beg', so we need to redefine syntax for '/'."
|
|
|
|
(set-syntax-table (let* ((table (make-syntax-table)))
|
|
|
|
(modify-syntax-entry ?/ "." table)
|
|
|
|
table)))
|