added stuff

This commit is contained in:
9ahmed 2021-04-15 20:28:40 +05:00
parent dc8d6aa9bc
commit 5bf7591cd3
49 changed files with 24338 additions and 1 deletions

View File

@ -0,0 +1,18 @@
This is the file .../info/dir, which contains the
topmost node of the Info hierarchy, called (dir)Top.
The first time you invoke Info you start off looking at this node.

File: dir, Node: Top This is the top of the INFO tree
This (the Directory node) gives a menu of major topics.
Typing "q" exits, "H" lists all Info commands, "d" returns here,
"h" gives a primer for first-timers,
"mEmacs<Return>" visits the Emacs manual, etc.
In Emacs, you can click mouse button 2 on a menu item or cross reference
to select it.
* Menu:
Emacs
* evil: (evil.info). Extensible vi layer for Emacs

View File

@ -0,0 +1,128 @@
;;; evil-autoloads.el --- automatically extracted autoloads -*- lexical-binding: t -*-
;;
;;; Code:
(add-to-list 'load-path (directory-file-name
(or (file-name-directory #$) (car load-path))))
;;;### (autoloads nil "evil-command-window" "evil-command-window.el"
;;;;;; (0 0 0 0))
;;; Generated autoloads from evil-command-window.el
(register-definition-prefixes "evil-command-window" '("evil-"))
;;;***
;;;### (autoloads nil "evil-commands" "evil-commands.el" (0 0 0 0))
;;; Generated autoloads from evil-commands.el
(register-definition-prefixes "evil-commands" '("evil-"))
;;;***
;;;### (autoloads nil "evil-common" "evil-common.el" (0 0 0 0))
;;; Generated autoloads from evil-common.el
(register-definition-prefixes "evil-common" '("bounds-of-evil-" "evil-" "forward-evil-"))
;;;***
;;;### (autoloads nil "evil-core" "evil-core.el" (0 0 0 0))
;;; Generated autoloads from evil-core.el
(autoload 'evil-mode "evil" nil t)
(register-definition-prefixes "evil-core" '("evil-" "turn-o"))
;;;***
;;;### (autoloads nil "evil-digraphs" "evil-digraphs.el" (0 0 0 0))
;;; Generated autoloads from evil-digraphs.el
(register-definition-prefixes "evil-digraphs" '("evil-digraph"))
;;;***
;;;### (autoloads nil "evil-ex" "evil-ex.el" (0 0 0 0))
;;; Generated autoloads from evil-ex.el
(register-definition-prefixes "evil-ex" '("evil-"))
;;;***
;;;### (autoloads nil "evil-integration" "evil-integration.el" (0
;;;;;; 0 0 0))
;;; Generated autoloads from evil-integration.el
(register-definition-prefixes "evil-integration" '("evil-"))
;;;***
;;;### (autoloads nil "evil-jumps" "evil-jumps.el" (0 0 0 0))
;;; Generated autoloads from evil-jumps.el
(register-definition-prefixes "evil-jumps" '("evil-"))
;;;***
;;;### (autoloads nil "evil-macros" "evil-macros.el" (0 0 0 0))
;;; Generated autoloads from evil-macros.el
(register-definition-prefixes "evil-macros" '("evil-"))
;;;***
;;;### (autoloads nil "evil-maps" "evil-maps.el" (0 0 0 0))
;;; Generated autoloads from evil-maps.el
(register-definition-prefixes "evil-maps" '("evil-"))
;;;***
;;;### (autoloads nil "evil-repeat" "evil-repeat.el" (0 0 0 0))
;;; Generated autoloads from evil-repeat.el
(register-definition-prefixes "evil-repeat" '("evil-"))
;;;***
;;;### (autoloads nil "evil-search" "evil-search.el" (0 0 0 0))
;;; Generated autoloads from evil-search.el
(register-definition-prefixes "evil-search" '("evil-"))
;;;***
;;;### (autoloads nil "evil-states" "evil-states.el" (0 0 0 0))
;;; Generated autoloads from evil-states.el
(register-definition-prefixes "evil-states" '("evil-"))
;;;***
;;;### (autoloads nil "evil-types" "evil-types.el" (0 0 0 0))
;;; Generated autoloads from evil-types.el
(register-definition-prefixes "evil-types" '("evil-ex-get-optional-register-and-count"))
;;;***
;;;### (autoloads nil "evil-vars" "evil-vars.el" (0 0 0 0))
;;; Generated autoloads from evil-vars.el
(register-definition-prefixes "evil-vars" '("evil-"))
;;;***
;;;### (autoloads nil nil ("evil-development.el" "evil-keybindings.el"
;;;;;; "evil-pkg.el" "evil.el") (0 0 0 0))
;;;***
;; Local Variables:
;; version-control: never
;; no-byte-compile: t
;; no-update-autoloads: t
;; coding: utf-8
;; End:
;;; evil-autoloads.el ends here

View File

@ -0,0 +1,189 @@
;;; evil-command-window.el --- Evil command line window implementation -*- lexical-binding: t -*-
;; Author: Emanuel Evans <emanuel.evans at gmail.com>
;; Maintainer: Vegard Øye <vegard_oye at hotmail.com>
;; Version: 1.14.0
;;
;; This file is NOT part of GNU Emacs.
;;; License:
;; This file is part of Evil.
;;
;; Evil is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; Evil is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with Evil. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; This provides an implementation of the vim command line window for
;; editing and repeating past ex commands and searches.
;;; Code:
(require 'evil-vars)
(require 'evil-common)
(require 'evil-search)
(require 'evil-ex)
(defvar evil-search-module)
(define-derived-mode evil-command-window-mode fundamental-mode "Evil-cmd"
"Major mode for the Evil command line window."
(auto-fill-mode 0)
(setq-local after-change-functions (cons 'evil-command-window-draw-prefix
after-change-functions)))
(defun evil-command-window (hist cmd-key execute-fn)
"Open a command line window for HIST with CMD-KEY and EXECUTE-FN.
HIST should be a list of commands. CMD-KEY should be the string of
the key whose history is being shown (one of \":\", \"/\", or
\"?\"). EXECUTE-FN should be a function of one argument to
execute on the result that the user selects."
(when (eq major-mode 'evil-command-window-mode)
(user-error "Cannot recursively open command line window"))
(dolist (win (window-list))
(when (equal (buffer-name (window-buffer win))
"*Command Line*")
(kill-buffer (window-buffer win))
(delete-window win)))
(split-window nil
(unless (zerop evil-command-window-height)
evil-command-window-height)
'above)
(setq evil-command-window-current-buffer (current-buffer))
(ignore-errors (kill-buffer "*Command Line*"))
(switch-to-buffer "*Command Line*")
(setq-local evil-command-window-execute-fn execute-fn)
(setq-local evil-command-window-cmd-key cmd-key)
(evil-command-window-mode)
(evil-command-window-insert-commands hist))
(defun evil-command-window-ex (&optional current-command execute-fn)
"Open a command line window for editing and executing ex commands.
If CURRENT-COMMAND is present, it will be inserted under the
cursor as the current command to be edited. If EXECUTE-FN is given,
it will be used as the function to execute instead of
`evil-command-window-ex-execute', the default."
(interactive)
(evil-command-window (cons (or current-command "") evil-ex-history)
":"
(or execute-fn 'evil-command-window-ex-execute)))
(defun evil-ex-command-window ()
"Start command window with ex history and current minibuffer content."
(interactive)
(let ((current (minibuffer-contents))
(config (current-window-configuration)))
(evil-ex-teardown)
(select-window (minibuffer-selected-window) t)
(evil-command-window-ex current (apply-partially 'evil-ex-command-window-execute config))))
(defun evil-ex-search-command-window ()
"Start command window with search history and current minibuffer content."
(interactive)
(let ((current (minibuffer-contents))
(config (current-window-configuration)))
(select-window (minibuffer-selected-window) t)
(evil-command-window (cons current evil-ex-search-history)
(evil-search-prompt (eq evil-ex-search-direction 'forward))
(apply-partially 'evil-ex-command-window-execute config))))
(defun evil-command-window-execute ()
"Execute the command under the cursor in the appropriate buffer.
The local var `evil-command-window-execute-fn' determines which
function to execute."
(interactive)
(let ((result (buffer-substring (line-beginning-position)
(line-end-position)))
(execute-fn evil-command-window-execute-fn)
(command-window (get-buffer-window)))
(select-window (previous-window))
(unless (equal evil-command-window-current-buffer (current-buffer))
(user-error "Originating buffer is no longer active"))
(kill-buffer "*Command Line*")
(delete-window command-window)
(funcall execute-fn result)
(setq evil-command-window-current-buffer nil)))
(defun evil-command-window-ex-execute (result)
"Execute RESULT as an ex command in the appropriate buffer."
(unless (string-match-p "^ *$" result)
(unless (equal result (car evil-ex-history))
(setq evil-ex-history (cons result evil-ex-history)))
(let ((evil-ex-current-buffer evil-command-window-current-buffer))
(evil-ex-execute result))))
(defun evil-command-window-search-forward ()
"Open a command line window for forward searches."
(interactive)
(evil-command-window (cons ""
(if (eq evil-search-module 'evil-search)
evil-ex-search-history
evil-search-forward-history))
"/"
(lambda (result)
(evil-command-window-search-execute result t))))
(defun evil-command-window-search-backward ()
"Open a command line window for backward searches."
(interactive)
(evil-command-window (cons ""
(if (eq evil-search-module 'evil-search)
evil-ex-search-history
evil-search-backward-history))
"?"
(lambda (result)
(evil-command-window-search-execute result nil))))
(defun evil-command-window-search-execute (result forward)
"Search for RESULT using FORWARD to determine direction."
(unless (zerop (length result))
(if (eq evil-search-module 'evil-search)
(progn
(setq evil-ex-search-pattern (evil-ex-make-search-pattern result)
evil-ex-search-direction (if forward 'forward 'backward))
(unless (equal result (car-safe evil-ex-search-history))
(push result evil-ex-search-history))
(evil-ex-search))
(if forward
(unless (equal result (car-safe evil-search-forward-history))
(push result evil-search-forward-history))
(unless (equal result (car-safe evil-search-backward-history))
(push result evil-search-backward-history)))
(evil-search result forward evil-regexp-search))))
(defun evil-command-window-draw-prefix (&rest ignored)
"Display `evil-command-window-cmd-key' as a prefix to the current line.
Parameters passed in through IGNORED are ignored."
(let ((prefix (propertize evil-command-window-cmd-key
'font-lock-face 'minibuffer-prompt)))
(set-text-properties (line-beginning-position) (line-beginning-position 2)
(list 'line-prefix prefix))))
(defun evil-command-window-insert-commands (hist)
"Insert the commands in HIST."
(let ((inhibit-modification-hooks t))
(mapc #'(lambda (cmd) (insert cmd) (newline)) hist)
(reverse-region (point-min) (point-max)))
(let ((prefix (propertize evil-command-window-cmd-key
'font-lock-face 'minibuffer-prompt)))
(set-text-properties (point-min) (point-max) (list 'line-prefix prefix)))
(goto-char (point-max))
(when (and (bolp) (not (bobp))) (backward-char))
(evil-adjust-cursor))
(provide 'evil-command-window)
;;; evil-command-window.el ends here

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -0,0 +1,50 @@
;;; evil-development.el --- Useful features for Evil developers -*- lexical-binding: t -*-
;; Author: Justin Burkett <justin at burkett dot cc>
;; Version: 1.14.0
;;
;; This file is NOT part of GNU Emacs.
;;; License:
;; This file is part of Evil.
;;
;; Evil is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; Evil is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with Evil. If not, see <http://www.gnu.org/licenses/>.
;;; Code:
;;; Teach imenu about evil macros
(with-eval-after-load 'lisp-mode
(when (boundp 'lisp-imenu-generic-expression)
(dolist (macro '("interactive-code"
"type"
"text-object"
"motion"
"command"
"operator"))
(let ((macro-name (format "evil-%s" macro)))
(unless (assoc macro-name lisp-imenu-generic-expression)
(push (list
macro-name
(format "^\\s-*(evil-define-%s\\s-+\\(\\(?:\\sw\\|\\s_\\|\\\\.\\)+\\)"
macro)
1)
lisp-imenu-generic-expression))))))
(provide 'evil-development)
;;; evil-development.el ends here

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -0,0 +1,524 @@
;;; evil-integration.el --- Integrate Evil with other modules -*- lexical-binding: t -*-
;; Author: Vegard Øye <vegard_oye at hotmail.com>
;; Maintainer: Vegard Øye <vegard_oye at hotmail.com>
;; Version: 1.14.0
;;
;; This file is NOT part of GNU Emacs.
;;; License:
;; This file is part of Evil.
;;
;; Evil is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; Evil is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with Evil. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; This provides evil integration for various emacs modes.
;; Additional keybindings (or default state) should go into evil-keybindings.el.
;;; Code:
(require 'evil-maps)
(require 'evil-core)
(require 'evil-macros)
(require 'evil-types)
(require 'evil-repeat)
;;; Evilize some commands
;; unbound keys should be ignored
(evil-declare-ignore-repeat 'undefined)
(mapc #'(lambda (cmd)
(evil-set-command-property cmd :keep-visual t)
(evil-declare-not-repeat cmd))
'(digit-argument
negative-argument
universal-argument
universal-argument-minus
universal-argument-more
universal-argument-other-key))
(mapc #'evil-declare-not-repeat
'(what-cursor-position))
(mapc #'evil-declare-change-repeat
'(dabbrev-expand
hippie-expand
quoted-insert))
(mapc #'evil-declare-abort-repeat
'(balance-windows
eval-expression
execute-extended-command
exit-minibuffer
compile
delete-window
delete-other-windows
find-file-at-point
ffap-other-window
recompile
redo
save-buffer
split-window
split-window-horizontally
split-window-vertically
undo
undo-tree-redo
undo-tree-undo))
(evil-set-type #'previous-line 'line)
(evil-set-type #'next-line 'line)
(dolist (cmd '(keyboard-quit keyboard-escape-quit))
(evil-set-command-property cmd :suppress-operator t))
;;; Mouse
(evil-declare-insert-at-point-repeat 'mouse-yank-primary)
(evil-declare-insert-at-point-repeat 'mouse-yank-secondary)
;;; key-binding
;; Calling `keyboard-quit' should cancel repeat
(defadvice keyboard-quit (before evil activate)
(when (fboundp 'evil-repeat-abort)
(evil-repeat-abort)))
(eval-after-load 'wdired
'(progn
(add-hook 'wdired-mode-hook #'evil-change-to-initial-state)
(defadvice wdired-change-to-dired-mode (after evil activate)
(evil-change-to-initial-state nil t))))
;;; Parentheses
(defadvice show-paren-function (around evil disable)
"Match parentheses in Normal state."
(if (if (memq 'not evil-highlight-closing-paren-at-point-states)
(memq evil-state evil-highlight-closing-paren-at-point-states)
(not (memq evil-state evil-highlight-closing-paren-at-point-states)))
ad-do-it
(let ((pos (point)) syntax narrow)
(setq pos
(catch 'end
(dotimes (var (1+ (* 2 evil-show-paren-range)))
(if (zerop (mod var 2))
(setq pos (+ pos var))
(setq pos (- pos var)))
(setq syntax (syntax-class (syntax-after pos)))
(cond
((eq syntax 4)
(setq narrow pos)
(throw 'end pos))
((eq syntax 5)
(throw 'end (1+ pos)))))))
(if pos
(save-excursion
(goto-char pos)
(save-restriction
(when narrow
(narrow-to-region narrow (point-max)))
ad-do-it))
;; prevent the preceding pair from being highlighted
(dolist (ov '(show-paren--overlay
show-paren--overlay-1
show-paren-overlay
show-paren-overlay-1))
(let ((ov (and (boundp ov) (symbol-value ov))))
(when (overlayp ov) (delete-overlay ov))))))))
;;; Undo tree
(eval-after-load 'undo-tree
'(with-no-warnings
(defadvice undo-tree-visualize (after evil activate)
"Initialize Evil in the visualization buffer."
(when evil-local-mode
(evil-initialize-state)))
(when (fboundp 'undo-tree-visualize)
(evil-ex-define-cmd "undol[ist]" 'undo-tree-visualize)
(evil-ex-define-cmd "ul" 'undo-tree-visualize))
(when (boundp 'undo-tree-visualizer-mode-map)
(define-key undo-tree-visualizer-mode-map
[remap evil-backward-char] 'undo-tree-visualize-switch-branch-left)
(define-key undo-tree-visualizer-mode-map
[remap evil-forward-char] 'undo-tree-visualize-switch-branch-right)
(define-key undo-tree-visualizer-mode-map
[remap evil-next-line] 'undo-tree-visualize-redo)
(define-key undo-tree-visualizer-mode-map
[remap evil-previous-line] 'undo-tree-visualize-undo)
(define-key undo-tree-visualizer-mode-map
[remap evil-ret] 'undo-tree-visualizer-set))
(when (boundp 'undo-tree-visualizer-selection-mode-map)
(define-key undo-tree-visualizer-selection-mode-map
[remap evil-backward-char] 'undo-tree-visualizer-select-left)
(define-key undo-tree-visualizer-selection-mode-map
[remap evil-forward-char] 'undo-tree-visualizer-select-right)
(define-key undo-tree-visualizer-selection-mode-map
[remap evil-next-line] 'undo-tree-visualizer-select-next)
(define-key undo-tree-visualizer-selection-mode-map
[remap evil-previous-line] 'undo-tree-visualizer-select-previous)
(define-key undo-tree-visualizer-selection-mode-map
[remap evil-ret] 'undo-tree-visualizer-set))))
;;; Auto-complete
(eval-after-load 'auto-complete
'(progn
(evil-add-command-properties 'auto-complete :repeat 'evil-ac-repeat)
(evil-add-command-properties 'ac-complete :repeat 'evil-ac-repeat)
(evil-add-command-properties 'ac-expand :repeat 'evil-ac-repeat)
(evil-add-command-properties 'ac-next :repeat 'ignore)
(evil-add-command-properties 'ac-previous :repeat 'ignore)
(defvar evil-ac-prefix-len nil
"The length of the prefix of the current item to be completed.")
(defvar ac-prefix)
(defun evil-ac-repeat (flag)
"Record the changes for auto-completion."
(cond
((eq flag 'pre)
(setq evil-ac-prefix-len (length ac-prefix))
(evil-repeat-start-record-changes))
((eq flag 'post)
;; Add change to remove the prefix
(evil-repeat-record-change (- evil-ac-prefix-len)
""
evil-ac-prefix-len)
;; Add change to insert the full completed text
(evil-repeat-record-change
(- evil-ac-prefix-len)
(buffer-substring-no-properties (- evil-repeat-pos
evil-ac-prefix-len)
(point))
0)
;; Finish repeation
(evil-repeat-finish-record-changes))))))
;;; Company
(eval-after-load 'company
'(progn
(mapc #'evil-declare-change-repeat
'(company-complete-mouse
company-complete-number
company-complete-selection
company-complete-common))
(mapc #'evil-declare-ignore-repeat
'(company-abort
company-select-next
company-select-previous
company-select-next-or-abort
company-select-previous-or-abort
company-select-mouse
company-show-doc-buffer
company-show-location
company-search-candidates
company-filter-candidates))))
;; Eval last sexp
(cond
((version< emacs-version "25")
(defadvice preceding-sexp (around evil activate)
"In normal-state or motion-state, last sexp ends at point."
(if (and (not evil-move-beyond-eol)
(or (evil-normal-state-p) (evil-motion-state-p)))
(save-excursion
(unless (or (eobp) (eolp)) (forward-char))
ad-do-it)
ad-do-it))
(defadvice pp-last-sexp (around evil activate)
"In normal-state or motion-state, last sexp ends at point."
(if (and (not evil-move-beyond-eol)
(or (evil-normal-state-p) (evil-motion-state-p)))
(save-excursion
(unless (or (eobp) (eolp)) (forward-char))
ad-do-it)
ad-do-it)))
(t
(defun evil--preceding-sexp (command &rest args)
"In normal-state or motion-state, last sexp ends at point."
(if (and (not evil-move-beyond-eol)
(or (evil-normal-state-p) (evil-motion-state-p)))
(save-excursion
(unless (or (eobp) (eolp)) (forward-char))
(apply command args))
(apply command args)))
(advice-add 'elisp--preceding-sexp :around 'evil--preceding-sexp '((name . evil)))
(advice-add 'pp-last-sexp :around 'evil--preceding-sexp '((name . evil)))))
;; Show key
(defadvice quail-show-key (around evil activate)
"Temporarily go to Emacs state"
(evil-with-state emacs ad-do-it))
(defadvice describe-char (around evil activate)
"Temporarily go to Emacs state"
(evil-with-state emacs ad-do-it))
;; ace-jump-mode
(declare-function ace-jump-char-mode "ext:ace-jump-mode")
(declare-function ace-jump-word-mode "ext:ace-jump-mode")
(declare-function ace-jump-line-mode "ext:ace-jump-mode")
(defvar ace-jump-mode-scope)
(defvar evil-ace-jump-active nil)
(defmacro evil-enclose-ace-jump-for-motion (&rest body)
"Enclose ace-jump to make it suitable for motions.
This includes restricting `ace-jump-mode' to the current window
in visual and operator state, deactivating visual updates, saving
the mark and entering `recursive-edit'."
(declare (indent defun)
(debug t))
`(let ((old-mark (mark))
(ace-jump-mode-scope
(if (and (not (memq evil-state '(visual operator)))
(boundp 'ace-jump-mode-scope))
ace-jump-mode-scope
'window)))
(remove-hook 'pre-command-hook #'evil-visual-pre-command t)
(remove-hook 'post-command-hook #'evil-visual-post-command t)
(unwind-protect
(let ((evil-ace-jump-active 'prepare))
(add-hook 'ace-jump-mode-end-hook
#'evil-ace-jump-exit-recursive-edit)
,@body
(when evil-ace-jump-active
(setq evil-ace-jump-active t)
(recursive-edit)))
(remove-hook 'post-command-hook
#'evil-ace-jump-exit-recursive-edit)
(remove-hook 'ace-jump-mode-end-hook
#'evil-ace-jump-exit-recursive-edit)
(if (evil-visual-state-p)
(progn
(add-hook 'pre-command-hook #'evil-visual-pre-command nil t)
(add-hook 'post-command-hook #'evil-visual-post-command nil t)
(set-mark old-mark))
(push-mark old-mark)))))
(eval-after-load 'ace-jump-mode
`(defadvice ace-jump-done (after evil activate)
(when evil-ace-jump-active
(add-hook 'post-command-hook #'evil-ace-jump-exit-recursive-edit))))
(defun evil-ace-jump-exit-recursive-edit ()
"Exit a recursive edit caused by an evil jump."
(cond
((eq evil-ace-jump-active 'prepare)
(setq evil-ace-jump-active nil))
(evil-ace-jump-active
(remove-hook 'post-command-hook #'evil-ace-jump-exit-recursive-edit)
(exit-recursive-edit))))
(evil-define-motion evil-ace-jump-char-mode (count)
"Jump visually directly to a char using ace-jump."
:type inclusive
(evil-without-repeat
(let ((pnt (point))
(buf (current-buffer)))
(evil-enclose-ace-jump-for-motion
(call-interactively 'ace-jump-char-mode))
;; if we jump backwards, motion type is exclusive, analogously
;; to `evil-find-char-backward'
(when (and (equal buf (current-buffer))
(< (point) pnt))
(setq evil-this-type
(cond
((eq evil-this-type 'exclusive) 'inclusive)
((eq evil-this-type 'inclusive) 'exclusive)))))))
(evil-define-motion evil-ace-jump-char-to-mode (count)
"Jump visually to the char in front of a char using ace-jump."
:type inclusive
(evil-without-repeat
(let ((pnt (point))
(buf (current-buffer)))
(evil-enclose-ace-jump-for-motion
(call-interactively 'ace-jump-char-mode))
(if (and (equal buf (current-buffer))
(< (point) pnt))
(progn
(or (eobp) (forward-char))
(setq evil-this-type
(cond
((eq evil-this-type 'exclusive) 'inclusive)
((eq evil-this-type 'inclusive) 'exclusive))))
(backward-char)))))
(evil-define-motion evil-ace-jump-line-mode (count)
"Jump visually to the beginning of a line using ace-jump."
:type line
:repeat abort
(evil-without-repeat
(evil-enclose-ace-jump-for-motion
(call-interactively 'ace-jump-line-mode))))
(evil-define-motion evil-ace-jump-word-mode (count)
"Jump visually to the beginning of a word using ace-jump."
:type exclusive
:repeat abort
(evil-without-repeat
(evil-enclose-ace-jump-for-motion
(call-interactively 'ace-jump-word-mode))))
(define-key evil-motion-state-map [remap ace-jump-char-mode] #'evil-ace-jump-char-mode)
(define-key evil-motion-state-map [remap ace-jump-line-mode] #'evil-ace-jump-line-mode)
(define-key evil-motion-state-map [remap ace-jump-word-mode] #'evil-ace-jump-word-mode)
;;; avy
(declare-function avy-goto-word-or-subword-1 "ext:avy")
(declare-function avy-goto-line "ext:avy")
(declare-function avy-goto-char "ext:avy")
(declare-function avy-goto-char-2 "ext:avy")
(declare-function avy-goto-char-2-above "ext:avy")
(declare-function avy-goto-char-2-below "ext:avy")
(declare-function avy-goto-char-in-line "ext:avy")
(declare-function avy-goto-word-0 "ext:avy")
(declare-function avy-goto-word-1 "ext:avy")
(declare-function avy-goto-word-1-above "ext:avy")
(declare-function avy-goto-word-1-below "ext:avy")
(declare-function avy-goto-subword-0 "ext:avy")
(declare-function avy-goto-subword-1 "ext:avy")
(declare-function avy-goto-char-timer "ext:avy")
(defvar avy-all-windows)
(defmacro evil-enclose-avy-for-motion (&rest body)
"Enclose avy to make it suitable for motions.
Based on `evil-enclose-ace-jump-for-motion'."
(declare (indent defun)
(debug t))
`(let ((avy-all-windows
(if (and (not (memq evil-state '(visual operator)))
(boundp 'avy-all-windows))
avy-all-windows
nil)))
,@body))
(defmacro evil-define-avy-motion (command type)
(declare (indent defun)
(debug t))
(let ((name (intern (format "evil-%s" command))))
`(evil-define-motion ,name (count)
,(format "Evil motion for `%s'." command)
:type ,type
:jump t
:repeat abort
(evil-without-repeat
(evil-enclose-avy-for-motion
(call-interactively ',command))))))
;; define evil-avy-* motion commands for avy-* commands
(evil-define-avy-motion avy-goto-char inclusive)
(evil-define-avy-motion avy-goto-char-2 inclusive)
(evil-define-avy-motion avy-goto-char-2-above inclusive)
(evil-define-avy-motion avy-goto-char-2-below inclusive)
(evil-define-avy-motion avy-goto-char-in-line inclusive)
(evil-define-avy-motion avy-goto-char-timer inclusive)
(evil-define-avy-motion avy-goto-line line)
(evil-define-avy-motion avy-goto-line-above line)
(evil-define-avy-motion avy-goto-line-below line)
(evil-define-avy-motion avy-goto-subword-0 exclusive)
(evil-define-avy-motion avy-goto-subword-1 exclusive)
(evil-define-avy-motion avy-goto-symbol-1 exclusive)
(evil-define-avy-motion avy-goto-symbol-1-above exclusive)
(evil-define-avy-motion avy-goto-symbol-1-below exclusive)
(evil-define-avy-motion avy-goto-word-0 exclusive)
(evil-define-avy-motion avy-goto-word-1 exclusive)
(evil-define-avy-motion avy-goto-word-1-above exclusive)
(evil-define-avy-motion avy-goto-word-1-below exclusive)
(evil-define-avy-motion avy-goto-word-or-subword-1 exclusive)
;; remap avy-* commands to evil-avy-* commands
(dolist (command '(avy-goto-char
avy-goto-char-2
avy-goto-char-2-above
avy-goto-char-2-below
avy-goto-char-in-line
avy-goto-char-timer
avy-goto-line
avy-goto-line-above
avy-goto-line-below
avy-goto-subword-0
avy-goto-subword-1
avy-goto-symbol-1
avy-goto-symbol-1-above
avy-goto-symbol-1-below
avy-goto-word-0
avy-goto-word-1
avy-goto-word-1-above
avy-goto-word-1-below
avy-goto-word-or-subword-1))
(define-key evil-motion-state-map
(vector 'remap command) (intern-soft (format "evil-%s" command))))
;;; nXhtml/mumamo
;; ensure that mumamo does not toggle evil through its globalized mode
(eval-after-load 'mumamo
'(with-no-warnings
(push 'evil-mode-cmhh mumamo-change-major-mode-no-nos)))
;; visual-line-mode integration
(when evil-respect-visual-line-mode
(evil-define-command evil-digit-argument-or-evil-beginning-of-visual-line ()
:digit-argument-redirection evil-beginning-of-visual-line
:keep-visual t
:repeat nil
(interactive)
(cond
(current-prefix-arg
(setq this-command #'digit-argument)
(call-interactively #'digit-argument))
(t
(setq this-command 'evil-beginning-of-visual-line)
(call-interactively 'evil-beginning-of-visual-line))))
(evil-define-minor-mode-key 'motion 'visual-line-mode
"j" 'evil-next-visual-line
"gj" 'evil-next-line
"k" 'evil-previous-visual-line
"gk" 'evil-previous-line
"0" 'evil-digit-argument-or-evil-beginning-of-visual-line
"g0" 'evil-beginning-of-line
"$" 'evil-end-of-visual-line
"g$" 'evil-end-of-line
"V" 'evil-visual-screen-line))
;;; abbrev.el
(defun evil-maybe-expand-abbrev ()
(when (and abbrev-mode evil-want-abbrev-expand-on-insert-exit)
(expand-abbrev)))
(eval-after-load 'abbrev
'(add-hook 'evil-insert-state-exit-hook 'evil-maybe-expand-abbrev))
;;; ElDoc
(eval-after-load 'eldoc
'(when (fboundp 'eldoc-add-command-completions)
(eldoc-add-command-completions "evil-window-")))
;;; XRef
(eval-after-load 'xref
'(progn
(evil-set-command-property 'xref-find-definitions :jump t)
(evil-set-command-property 'xref-find-references :jump t)))
(provide 'evil-integration)
;;; evil-integration.el ends here

Binary file not shown.

View File

@ -0,0 +1,353 @@
;;; evil-jumps.el --- Jump list implementation -*- lexical-binding: t -*-
;; Author: Bailey Ling <bling at live.ca>
;; Version: 1.14.0
;;
;; This file is NOT part of GNU Emacs.
;;; License:
;; This file is part of Evil.
;;
;; Evil is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; Evil is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with Evil. If not, see <http://www.gnu.org/licenses/>.
(require 'cl-lib)
(require 'evil-core)
(require 'evil-states)
;;; Code:
(defgroup evil-jumps nil
"Evil jump list configuration options."
:prefix "evil-jumps"
:group 'evil)
(defcustom evil-jumps-cross-buffers t
"When non-nil, the jump commands can cross borders between buffers, otherwise the jump commands act only within the current buffer."
:type 'boolean
:group 'evil-jumps)
(defcustom evil-jumps-max-length 100
"The maximum number of jumps to keep track of."
:type 'integer
:group 'evil-jumps)
(defcustom evil-jumps-pre-jump-hook nil
"Hooks to run just before jumping to a location in the jump list."
:type 'hook
:group 'evil-jumps)
(defcustom evil-jumps-post-jump-hook nil
"Hooks to run just after jumping to a location in the jump list."
:type 'hook
:group 'evil-jumps)
(defcustom evil-jumps-ignored-file-patterns '("COMMIT_EDITMSG$" "TAGS$")
"A list of pattern regexps to match on the file path to exclude from being included in the jump list."
:type '(repeat string)
:group 'evil-jumps)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defvar savehist-additional-variables)
(defvar evil--jumps-jumping nil)
(defvar evil--jumps-jumping-backward nil
"Set by `evil--jump-backward', used and cleared in the
`post-command-hook' by `evil--jump-handle-buffer-crossing'")
(eval-when-compile (defvar evil--jumps-debug nil))
(defvar evil--jumps-buffer-targets "\\*\\(new\\|scratch\\)\\*"
"Regexp to match against `buffer-name' to determine whether it's a valid jump target.")
(defvar evil--jumps-window-jumps (make-hash-table)
"Hashtable which stores all jumps on a per window basis.")
(defvar evil-jumps-history nil
"History of `evil-mode' jumps that are persisted with `savehist'.")
(cl-defstruct evil-jumps-struct
ring
(idx -1)
previous-pos)
;; Is inlining this really worth it?
(defsubst evil--jumps-message (format &rest args)
(when (eval-when-compile evil--jumps-debug)
(with-current-buffer (get-buffer-create "*evil-jumps*")
(goto-char (point-max))
(insert (apply #'format format args) "\n"))))
(defun evil--jumps-get-current (&optional window)
(unless window
(setq window (frame-selected-window)))
(let* ((jump-struct (gethash window evil--jumps-window-jumps)))
(unless jump-struct
(setq jump-struct (make-evil-jumps-struct))
(puthash window jump-struct evil--jumps-window-jumps))
jump-struct))
(defun evil--jumps-get-jumps (struct)
(let ((ring (evil-jumps-struct-ring struct)))
(unless ring
(setq ring (make-ring evil-jumps-max-length))
(setf (evil-jumps-struct-ring struct) ring))
ring))
(defun evil--jumps-get-window-jump-list ()
(let ((struct (evil--jumps-get-current)))
(evil--jumps-get-jumps struct)))
(defun evil--jumps-savehist-load ()
(add-to-list 'savehist-additional-variables 'evil-jumps-history)
(let ((ring (make-ring evil-jumps-max-length)))
(cl-loop for jump in (reverse evil-jumps-history)
do (ring-insert ring jump))
(setf (evil-jumps-struct-ring (evil--jumps-get-current)) ring))
(add-hook 'savehist-save-hook #'evil--jumps-savehist-sync)
(remove-hook 'savehist-mode-hook #'evil--jumps-savehist-load))
(defun evil--jumps-savehist-sync ()
"Updates the printable value of window jumps for `savehist'."
(setq evil-jumps-history
(delq nil (mapcar #'(lambda (jump)
(let* ((mark (car jump))
(pos (if (markerp mark)
(marker-position mark)
mark))
(file-name (cadr jump)))
(when (and (not (file-remote-p file-name))
(file-exists-p file-name)
pos)
(list pos file-name))))
(ring-elements (evil--jumps-get-window-jump-list))))))
(defun evil--jumps-jump (idx shift)
(let ((target-list (evil--jumps-get-window-jump-list)))
(evil--jumps-message "jumping from %s by %s" idx shift)
(evil--jumps-message "target list = %s" target-list)
(setq idx (+ idx shift))
(let* ((current-file-name (or (buffer-file-name) (buffer-name)))
(size (ring-length target-list)))
(unless evil-jumps-cross-buffers
;; skip jump marks pointing to other buffers
(while (and (< idx size) (>= idx 0)
(not (string= current-file-name (cadr (ring-ref target-list idx)))))
(setq idx (+ idx shift))))
(when (and (< idx size) (>= idx 0))
;; actual jump
(run-hooks 'evil-jumps-pre-jump-hook)
(let* ((place (ring-ref target-list idx))
(pos (car place))
(file-name (cadr place)))
(setq evil--jumps-jumping t)
(if (string-match-p evil--jumps-buffer-targets file-name)
(switch-to-buffer file-name)
(find-file file-name))
(setq evil--jumps-jumping nil)
(goto-char pos)
(setf (evil-jumps-struct-idx (evil--jumps-get-current)) idx)
(run-hooks 'evil-jumps-post-jump-hook))))))
(defun evil--jumps-push ()
"Pushes the current cursor/file position to the jump list."
(let ((target-list (evil--jumps-get-window-jump-list)))
(let ((file-name (buffer-file-name))
(buffer-name (buffer-name))
(current-pos (point-marker))
(first-pos nil)
(first-file-name nil)
(excluded nil))
(when (and (not file-name)
(string-match-p evil--jumps-buffer-targets buffer-name))
(setq file-name buffer-name))
(when file-name
(dolist (pattern evil-jumps-ignored-file-patterns)
(when (string-match-p pattern file-name)
(setq excluded t)))
(unless excluded
(unless (ring-empty-p target-list)
(setq first-pos (car (ring-ref target-list 0)))
(setq first-file-name (car (cdr (ring-ref target-list 0)))))
(unless (and (equal first-pos current-pos)
(equal first-file-name file-name))
(evil--jumps-message "pushing %s on %s" current-pos file-name)
(ring-insert target-list `(,current-pos ,file-name))))))
(evil--jumps-message "%s %s"
(selected-window)
(and (not (ring-empty-p target-list))
(ring-ref target-list 0)))))
(evil-define-command evil-show-jumps ()
"Display the contents of the jump list."
:repeat nil
(evil-with-view-list
:name "evil-jumps"
:mode "Evil Jump List"
:format [("Jump" 5 nil)
("Marker" 8 nil)
("File/text" 1000 t)]
:entries (let* ((jumps (evil--jumps-savehist-sync))
(count 0))
(cl-loop for jump in jumps
collect `(nil [,(number-to-string (cl-incf count))
,(number-to-string (car jump))
(,(cadr jump))])))
:select-action #'evil--show-jumps-select-action))
(defun evil--show-jumps-select-action (jump)
(let ((position (string-to-number (elt jump 1)))
(file (car (elt jump 2))))
(kill-buffer)
(switch-to-buffer (find-file file))
(goto-char position)))
(defun evil-set-jump (&optional pos)
"Set jump point at POS.
POS defaults to point."
(save-excursion
(when (markerp pos)
(set-buffer (marker-buffer pos)))
(unless (or (region-active-p) (evil-visual-state-p))
(push-mark pos t))
(unless evil--jumps-jumping
;; clear out intermediary jumps when a new one is set
(let* ((struct (evil--jumps-get-current))
(target-list (evil--jumps-get-jumps struct))
(idx (evil-jumps-struct-idx struct)))
(cl-loop repeat idx
do (ring-remove target-list))
(setf (evil-jumps-struct-idx struct) -1))
(when pos
(goto-char pos))
(evil--jumps-push))))
(defun evil--jump-backward (count)
(setq evil--jumps-jumping-backward t)
(let ((count (or count 1)))
(evil-motion-loop (nil count)
(let* ((struct (evil--jumps-get-current))
(idx (evil-jumps-struct-idx struct)))
(evil--jumps-message "jumping back %s" idx)
(when (= idx -1)
(setq idx 0)
(setf (evil-jumps-struct-idx struct) 0)
(evil--jumps-push))
(evil--jumps-jump idx 1)))))
(defun evil--jump-forward (count)
(let ((count (or count 1)))
(evil-motion-loop (nil count)
(let* ((struct (evil--jumps-get-current))
(idx (evil-jumps-struct-idx struct)))
(when (= idx -1)
(setq idx 0)
(setf (evil-jumps-struct-idx struct) 0)
(evil--jumps-push))
(evil--jumps-jump idx -1)))))
(defun evil--jumps-window-configuration-hook (&rest _args)
(let* ((window-list (window-list-1 nil nil t))
(existing-window (selected-window))
(new-window (previous-window)))
(when (and (not (eq existing-window new-window))
(> (length window-list) 1))
(let* ((target-jump-struct (evil--jumps-get-current new-window)))
(if (not (ring-empty-p (evil--jumps-get-jumps target-jump-struct)))
(evil--jumps-message "target window %s already has %s jumps" new-window
(ring-length (evil--jumps-get-jumps target-jump-struct)))
(evil--jumps-message "new target window detected; copying %s to %s" existing-window new-window)
(let* ((source-jump-struct (evil--jumps-get-current existing-window))
(source-list (evil--jumps-get-jumps source-jump-struct)))
(when (= (ring-length (evil--jumps-get-jumps target-jump-struct)) 0)
(setf (evil-jumps-struct-previous-pos target-jump-struct) (evil-jumps-struct-previous-pos source-jump-struct))
(setf (evil-jumps-struct-idx target-jump-struct) (evil-jumps-struct-idx source-jump-struct))
(setf (evil-jumps-struct-ring target-jump-struct) (ring-copy source-list)))))))
;; delete obsolete windows
(maphash (lambda (key _val)
(unless (member key window-list)
(evil--jumps-message "removing %s" key)
(remhash key evil--jumps-window-jumps)))
evil--jumps-window-jumps)))
(defun evil--jump-hook (&optional command)
"`pre-command-hook' for evil-jumps.
Set jump point if COMMAND has a non-nil `:jump' property. Otherwise,
save the current position in case the command being executed will
change the current buffer."
(setq command (or command this-command))
(if (evil-get-command-property command :jump)
(evil-set-jump)
(setf (evil-jumps-struct-previous-pos (evil--jumps-get-current))
(point-marker))))
(defun evil--jump-handle-buffer-crossing ()
(let ((jumping-backward evil--jumps-jumping-backward))
(setq evil--jumps-jumping-backward nil)
(dolist (frame (frame-list))
(dolist (window (window-list frame))
(let* ((struct (evil--jumps-get-current window))
(previous-pos (evil-jumps-struct-previous-pos struct)))
(when previous-pos
(setf (evil-jumps-struct-previous-pos struct) nil)
(if (and
;; `evil-jump-backward' (and other backward jumping
;; commands) needs to be handled specially. When
;; jumping backward multiple times, calling
;; `evil-set-jump' is always wrong: If you jump back
;; twice and we call `evil-set-jump' after the second
;; time, we clear the forward jump list and
;; `evil--jump-forward' won't work.
;; The first time you jump backward, setting a jump
;; point is sometimes correct. But we don't do it
;; here because this function is called after
;; `evil--jump-backward' has updated our position in
;; the jump list so, again, `evil-set-jump' would
;; break `evil--jump-forward'.
(not jumping-backward)
(let ((previous-buffer (marker-buffer previous-pos)))
(and previous-buffer
(not (eq previous-buffer (window-buffer window))))))
(evil-set-jump previous-pos)
(set-marker previous-pos nil))))))))
(if (bound-and-true-p savehist-loaded)
(evil--jumps-savehist-load)
(add-hook 'savehist-mode-hook #'evil--jumps-savehist-load))
(defun evil--jumps-install-or-uninstall ()
(if evil-local-mode
(progn
(add-hook 'pre-command-hook #'evil--jump-hook nil t)
(add-hook 'post-command-hook #'evil--jump-handle-buffer-crossing nil t)
(add-hook 'next-error-hook #'evil-set-jump nil t)
(add-hook 'window-configuration-change-hook #'evil--jumps-window-configuration-hook nil t))
(remove-hook 'pre-command-hook #'evil--jump-hook t)
(remove-hook 'post-command-hook #'evil--jump-handle-buffer-crossing t)
(remove-hook 'next-error-hook #'evil-set-jump t)
(remove-hook 'window-configuration-change-hook #'evil--jumps-window-configuration-hook t)
(evil--jump-handle-buffer-crossing)))
(add-hook 'evil-local-mode-hook #'evil--jumps-install-or-uninstall)
(provide 'evil-jumps)
;;; evil-jumps.el ends here

Binary file not shown.

View File

@ -0,0 +1,124 @@
;;; evil-keybindings.el --- Add some Evil keybindings to other modules -*- lexical-binding: t -*-
;; Author: Vegard Øye <vegard_oye at hotmail.com>
;; Maintainer: Vegard Øye <vegard_oye at hotmail.com>
;; Version: 1.14.0
;;
;; This file is NOT part of GNU Emacs.
;;; License:
;; This file is part of Evil.
;;
;; Evil is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; Evil is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with Evil. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; This provides a set of keybindings for other emacs modes. This also includes
;; setting up the initial evil state of those other modes.
;;; Code:
(require 'evil-maps)
(require 'evil-core)
(require 'evil-macros)
(require 'evil-types)
(require 'evil-repeat)
;; etags-select
;; FIXME: probably etags-select should be recomended in docs
(eval-after-load 'etags-select
'(progn
(define-key evil-motion-state-map "g]" 'etags-select-find-tag-at-point)))
;;; Buffer-menu
(evil-add-hjkl-bindings Buffer-menu-mode-map 'motion)
;; dictionary.el
(evil-add-hjkl-bindings dictionary-mode-map 'motion
"?" 'dictionary-help ; "h"
"C-o" 'dictionary-previous) ; "l"
;;; Dired
(eval-after-load 'dired
'(progn
;; use the standard Dired bindings as a base
(defvar dired-mode-map)
(evil-make-overriding-map dired-mode-map 'normal)
(evil-add-hjkl-bindings dired-mode-map 'normal
"J" 'dired-goto-file ; "j"
"K" 'dired-do-kill-lines ; "k"
"r" 'dired-do-redisplay ; "l"
;; ":d", ":v", ":s", ":e"
";" (lookup-key dired-mode-map ":"))))
;;; ERT
(evil-add-hjkl-bindings ert-results-mode-map 'motion)
;;; Info
(evil-add-hjkl-bindings Info-mode-map 'motion
"0" 'evil-digit-argument-or-evil-beginning-of-line
(kbd "\M-h") 'Info-help ; "h"
"\C-t" 'Info-history-back ; "l"
"\C-o" 'Info-history-back
" " 'Info-scroll-up
"\C-]" 'Info-follow-nearest-node
(kbd "DEL") 'Info-scroll-down)
;;; Speedbar
(evil-add-hjkl-bindings speedbar-key-map 'motion
"h" 'backward-char
"j" 'speedbar-next
"k" 'speedbar-prev
"l" 'forward-char
"i" 'speedbar-item-info
"r" 'speedbar-refresh
"u" 'speedbar-up-directory
"o" 'speedbar-toggle-line-expansion
(kbd "RET") 'speedbar-edit-line)
;; Ibuffer
(eval-after-load 'ibuffer
'(progn
(defvar ibuffer-mode-map)
(evil-make-overriding-map ibuffer-mode-map 'normal)
(evil-define-key 'normal ibuffer-mode-map
"j" 'evil-next-line
"k" 'evil-previous-line
"RET" 'ibuffer-visit-buffer)))
;;; ag.el
(eval-after-load 'ag
'(progn
(defvar ag-mode-map)
(add-to-list 'evil-motion-state-modes 'ag-mode)
(evil-add-hjkl-bindings ag-mode-map 'motion)))
;;; ELP
(eval-after-load 'elp
'(defadvice elp-results (after evil activate)
(evil-motion-state)))
(provide 'evil-keybindings)
;;; evil-keybindings.el ends here

Binary file not shown.

View File

@ -0,0 +1,814 @@
;;; evil-macros.el --- Macros -*- lexical-binding: t -*-
;; Author: Vegard Øye <vegard_oye at hotmail.com>
;; Maintainer: Vegard Øye <vegard_oye at hotmail.com>
;; Version: 1.14.0
;;
;; This file is NOT part of GNU Emacs.
;;; License:
;; This file is part of Evil.
;;
;; Evil is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; Evil is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with Evil. If not, see <http://www.gnu.org/licenses/>.
(require 'evil-common)
(require 'evil-states)
(require 'evil-repeat)
;;; Code:
(declare-function evil-ex-p "evil-ex")
;; set some error codes
(put 'beginning-of-line 'error-conditions '(beginning-of-line error))
(put 'beginning-of-line 'error-message "Beginning of line")
(put 'end-of-line 'error-conditions '(end-of-line error))
(put 'end-of-line 'error-message "End of line")
(defun evil-motion-range (motion &optional count type)
"Execute a motion and return the buffer positions.
The return value is a list (BEG END TYPE)."
(let ((opoint (point))
(omark (mark t))
(obuffer (current-buffer))
(evil-motion-marker (move-marker (make-marker) (point)))
range)
(evil-with-transient-mark-mode
(evil-narrow-to-field
(unwind-protect
(let ((current-prefix-arg count)
;; Store type in global variable `evil-this-type'.
;; If necessary, motions can change their type
;; during execution by setting this variable.
(evil-this-type
(or type (evil-type motion 'exclusive))))
(condition-case err
(let ((repeat-type (evil-repeat-type motion t)))
(if (functionp repeat-type)
(funcall repeat-type 'pre))
(unless (with-local-quit
(setq range (call-interactively motion))
t)
(evil-repeat-abort)
(setq quit-flag t))
(if (functionp repeat-type)
(funcall repeat-type 'post)))
(error (prog1 nil
(evil-repeat-abort)
;; some operators depend on succeeding
;; motions, in particular for
;; `evil-forward-char' (e.g., used by
;; `evil-substitute'), therefore we let
;; end-of-line and end-of-buffer pass
(if (not (memq (car err) '(end-of-line end-of-buffer)))
(signal (car err) (cdr err))
(message (error-message-string err))))))
(cond
;; the motion returned a range
((evil-range-p range))
;; the motion made a Visual selection
((evil-visual-state-p)
(setq range (evil-visual-range)))
;; the motion made an active region
((region-active-p)
(setq range (evil-range (region-beginning)
(region-end)
evil-this-type)))
;; default: range from previous position to current
(t
(setq range (evil-expand-range
(evil-normalize evil-motion-marker
(point)
evil-this-type)))))
(unless (or (null type) (eq (evil-type range) type))
(evil-set-type range type)
(evil-expand-range range))
(evil-set-range-properties range nil)
range)
;; restore point and mark like `save-excursion',
;; but only if the motion hasn't disabled the operator
(unless evil-inhibit-operator
(set-buffer obuffer)
(evil-move-mark omark)
(goto-char opoint))
;; delete marker so it doesn't slow down editing
(move-marker evil-motion-marker nil))))))
(defmacro evil-define-motion (motion args &rest body)
"Define a motion command MOTION.
ARGS is a list of arguments. Motions can have any number of
arguments, but the first (if any) has the predefined meaning of
count. BODY must execute the motion by moving point.
Optional keyword arguments are:
- `:type' - determines how the motion works after an operator (one of
`inclusive', `line', `block' and `exclusive', or a self-defined
motion type)
- `:jump' - if non-nil, the previous position is stored in the jump
list, so that it can be restored with \
\\<evil-motion-state-map>\\[evil-jump-backward]
\(fn MOTION (COUNT ARGS...) DOC [[KEY VALUE]...] BODY...)"
(declare (indent defun)
(doc-string 3)
(debug (&define name lambda-list
[&optional stringp]
[&rest keywordp sexp]
[&optional ("interactive" [&rest form])]
def-body)))
(let (arg doc interactive key keys)
(when args
(setq args `(&optional ,@(delq '&optional args))
;; the count is either numerical or nil
interactive '("<c>")))
;; collect docstring
(when (and (> (length body) 1)
(or (eq (car-safe (car-safe body)) 'format)
(stringp (car-safe body))))
(setq doc (pop body)))
;; collect keywords
(setq keys (plist-put keys :repeat 'motion))
(while (keywordp (car-safe body))
(setq key (pop body)
arg (pop body)
keys (plist-put keys key arg)))
;; collect `interactive' specification
(when (eq (car-safe (car-safe body)) 'interactive)
(setq interactive (cdr (pop body))))
;; macro expansion
`(progn
;; refresh echo area in Eldoc mode
(when ',motion
(eval-after-load 'eldoc
'(and (fboundp 'eldoc-add-command)
(eldoc-add-command ',motion))))
(evil-define-command ,motion (,@args)
,@(when doc `(,doc)) ; avoid nil before `interactive'
,@keys
:keep-visual t
(interactive ,@interactive)
,@body))))
(defmacro evil-narrow-to-line (&rest body)
"Narrow BODY to the current line.
BODY will signal the errors 'beginning-of-line or 'end-of-line
upon reaching the beginning or end of the current line.
\(fn [[KEY VAL]...] BODY...)"
(declare (indent defun)
(debug t))
`(let* ((range (evil-expand (point) (point) 'line))
(beg (evil-range-beginning range))
(end (evil-range-end range))
(min (point-min))
(max (point-max)))
(when (save-excursion (goto-char end) (bolp))
(setq end (max beg (1- end))))
;; don't include the newline in Normal state
(when (and (not evil-move-beyond-eol)
(not (evil-visual-state-p))
(not (evil-operator-state-p)))
(setq end (max beg (1- end))))
(evil-with-restriction beg end
(evil-signal-without-movement
(condition-case err
(progn ,@body)
(beginning-of-buffer
(if (= beg min)
(signal (car err) (cdr err))
(signal 'beginning-of-line nil)))
(end-of-buffer
(if (= end max)
(signal (car err) (cdr err))
(signal 'end-of-line nil))))))))
;; we don't want line boundaries to trigger the debugger
;; when `debug-on-error' is t
(add-to-list 'debug-ignored-errors "^Beginning of line$")
(add-to-list 'debug-ignored-errors "^End of line$")
(defun evil-eobp (&optional pos)
"Whether point is at end-of-buffer with regard to end-of-line."
(save-excursion
(when pos (goto-char pos))
(cond
((eobp))
;; the rest only pertains to Normal state
((not (evil-normal-state-p))
nil)
;; at the end of the last line
((eolp)
(forward-char)
(eobp))
;; at the last character of the last line
(t
(forward-char)
(cond
((eobp))
((eolp)
(forward-char)
(eobp)))))))
(defun evil-move-beginning (count forward &optional backward)
"Move to the beginning of the COUNT next object.
If COUNT is negative, move to the COUNT previous object.
FORWARD is a function which moves to the end of the object, and
BACKWARD is a function which moves to the beginning.
If one is unspecified, the other is used with a negative argument."
(let* ((count (or count 1))
(backward (or backward
#'(lambda (count)
(funcall forward (- count)))))
(forward (or forward
#'(lambda (count)
(funcall backward (- count)))))
(opoint (point)))
(cond
((< count 0)
(when (bobp)
(signal 'beginning-of-buffer nil))
(unwind-protect
(evil-motion-loop (nil count count)
(funcall backward 1))
(unless (zerop count)
(goto-char (point-min)))))
((> count 0)
(when (evil-eobp)
(signal 'end-of-buffer nil))
;; Do we need to move past the current object?
(when (<= (save-excursion
(funcall forward 1)
(funcall backward 1)
(point))
opoint)
(setq count (1+ count)))
(unwind-protect
(evil-motion-loop (nil count count)
(funcall forward 1))
(if (zerop count)
;; go back to beginning of object
(funcall backward 1)
(goto-char (point-max)))))
(t
count))))
(defun evil-move-end (count forward &optional backward inclusive)
"Move to the end of the COUNT next object.
If COUNT is negative, move to the COUNT previous object.
FORWARD is a function which moves to the end of the object, and
BACKWARD is a function which moves to the beginning.
If one is unspecified, the other is used with a negative argument.
If INCLUSIVE is non-nil, then point is placed at the last character
of the object; otherwise it is placed at the end of the object."
(let* ((count (or count 1))
(backward (or backward
#'(lambda (count)
(funcall forward (- count)))))
(forward (or forward
#'(lambda (count)
(funcall backward (- count)))))
(opoint (point)))
(cond
((< count 0)
(when (bobp)
(signal 'beginning-of-buffer nil))
;; Do we need to move past the current object?
(when (>= (save-excursion
(funcall backward 1)
(funcall forward 1)
(point))
(if inclusive
(1+ opoint)
opoint))
(setq count (1- count)))
(unwind-protect
(evil-motion-loop (nil count count)
(funcall backward 1))
(if (not (zerop count))
(goto-char (point-min))
;; go to end of object
(funcall forward 1)
(when inclusive
(unless (bobp) (backward-char)))
(when (or (evil-normal-state-p)
(evil-motion-state-p))
(evil-adjust-cursor)))))
((> count 0)
(when (evil-eobp)
(signal 'end-of-buffer nil))
(when inclusive
(forward-char))
(unwind-protect
(evil-motion-loop (nil count count)
(funcall forward 1))
(if (not (zerop count))
(goto-char (point-max))
(when inclusive
(unless (bobp) (backward-char)))
(when (or (evil-normal-state-p)
(evil-motion-state-p))
(evil-adjust-cursor)))))
(t
count))))
(defun evil-text-object-make-linewise (range)
"Turn the text object selection RANGE to linewise.
The selection is adjusted in a sensible way so that the selected
lines match the user intent. In particular, whitespace-only parts
at the first and last lines are omitted. This function returns
the new range."
;; Bug #607
;; If new type is linewise and the selection of the
;; first line consists of whitespace only, the
;; beginning is moved to the start of the next line. If
;; the selections of the last line consists of
;; whitespace only, the end is moved to the end of the
;; previous line.
(if (eq (evil-type range) 'line)
range
(let ((expanded (plist-get (evil-range-properties range) :expanded))
(newrange (evil-expand-range range t)))
(save-excursion
;; skip whitespace at the beginning
(goto-char (evil-range-beginning newrange))
(skip-chars-forward " \t")
(when (and (not (bolp)) (eolp))
(evil-set-range-beginning newrange (1+ (point))))
;; skip whitepsace at the end
(goto-char (evil-range-end newrange))
(skip-chars-backward " \t")
(when (and (not (eolp)) (bolp))
(evil-set-range-end newrange (1- (point))))
;; only modify range if result is not empty
(if (> (evil-range-beginning newrange)
(evil-range-end newrange))
range
(unless expanded
(evil-contract-range newrange))
newrange)))))
(defmacro evil-define-text-object (object args &rest body)
"Define a text object command OBJECT.
BODY should return a range (BEG END) to the right of point
if COUNT is positive, and to the left of it if negative.
Optional keyword arguments:
- `:type' - determines how the range applies after an operator
(`inclusive', `line', `block', and `exclusive', or a self-defined
motion type).
- `:extend-selection' - if non-nil (default), the text object always
enlarges the current selection. Otherwise, it replaces the current
selection.
\(fn OBJECT (COUNT) DOC [[KEY VALUE]...] BODY...)"
(declare (indent defun)
(doc-string 3)
(debug (&define name lambda-list
[&optional stringp]
[&rest keywordp sexp]
def-body)))
(let* ((args (delq '&optional args))
(count (or (pop args) 'count))
(args (when args `(&optional ,@args)))
(interactive '((interactive "<c><v>")))
arg doc key keys)
;; collect docstring
(when (stringp (car-safe body))
(setq doc (pop body)))
;; collect keywords
(setq keys (plist-put keys :extend-selection t))
(while (keywordp (car-safe body))
(setq key (pop body)
arg (pop body)
keys (plist-put keys key arg)))
;; interactive
(when (eq (car-safe (car-safe body)) 'interactive)
(setq interactive (list (pop body))))
;; macro expansion
`(evil-define-motion ,object (,count ,@args)
,@(when doc `(,doc))
,@keys
,@interactive
(setq ,count (or ,count 1))
(when (/= ,count 0)
(let ((type (evil-type ',object evil-visual-char))
(extend (and (evil-visual-state-p)
(evil-get-command-property
',object :extend-selection
',(plist-get keys :extend-selection))))
(dir evil-visual-direction)
mark point range selection)
(cond
;; Visual state: extend the current selection
((and (evil-visual-state-p)
(called-interactively-p 'any))
;; if we are at the beginning of the Visual selection,
;; go to the left (negative COUNT); if at the end,
;; go to the right (positive COUNT)
(setq dir evil-visual-direction
,count (* ,count dir))
(setq range (progn ,@body))
(when (evil-range-p range)
(setq range (evil-expand-range range))
(evil-set-type range (evil-type range type))
(setq range (evil-contract-range range))
;; the beginning is mark and the end is point
;; unless the selection goes the other way
(setq mark (evil-range-beginning range)
point (evil-range-end range)
type (evil-type
(if evil-text-object-change-visual-type
range
(evil-visual-range))))
(when (and (eq type 'line)
(not (eq type (evil-type range))))
(let ((newrange (evil-text-object-make-linewise range)))
(setq mark (evil-range-beginning newrange)
point (evil-range-end newrange))))
(when (< dir 0)
(evil-swap mark point))
;; select the union
(evil-visual-make-selection mark point type)))
;; not Visual state: return a pair of buffer positions
(t
(setq range (progn ,@body))
(unless (evil-range-p range)
(setq ,count (- ,count)
range (progn ,@body)))
(when (evil-range-p range)
(setq selection (evil-range (point) (point) type))
(if extend
(setq range (evil-range-union range selection))
(evil-set-type range (evil-type range type)))
;; possibly convert to linewise
(when (eq evil-this-type-modified 'line)
(setq range (evil-text-object-make-linewise range)))
(evil-set-range-properties range nil)
range))))))))
(defmacro evil-define-operator (operator args &rest body)
"Define an operator command OPERATOR.
The operator acts on the range of characters BEG through
END. BODY must execute the operator by potentially manipulating
the buffer contents, or otherwise causing side effects to happen.
Optional keyword arguments are:
- `:type' - force the input range to be of a given type (`inclusive',
`line', `block', and `exclusive', or a self-defined motion type).
- `:motion' - use a predetermined motion instead of waiting for one
from the keyboard. This does not affect the behavior in visual
state, where selection boundaries are always used.
- `:repeat' - if non-nil (default), then \
\\<evil-normal-state-map>\\[evil-repeat] will repeat the
operator.
- `:move-point' - if non-nil (default), the cursor will be moved to
the beginning of the range before the body executes
- `:keep-visual' - if non-nil, the selection is not disabled when the
operator is executed in visual state. By default, visual state is
exited automatically.
\(fn OPERATOR (BEG END ARGS...) DOC [[KEY VALUE]...] BODY...)"
(declare (indent defun)
(doc-string 3)
(debug (&define name lambda-list
[&optional stringp]
[&rest keywordp sexp]
[&optional ("interactive" [&rest form])]
def-body)))
(let* ((args (delq '&optional args))
(interactive (if (> (length args) 2) '("<R>") '("<r>")))
(args (if (> (length args) 2)
`(,(nth 0 args) ,(nth 1 args)
&optional ,@(nthcdr 2 args))
args))
arg doc key keys visual)
;; collect docstring
(when (and (> (length body) 1)
(or (eq (car-safe (car-safe body)) 'format)
(stringp (car-safe body))))
(setq doc (pop body)))
;; collect keywords
(setq keys (plist-put keys :move-point t))
(while (keywordp (car-safe body))
(setq key (pop body)
arg (pop body))
(cond
((eq key :keep-visual)
(setq visual arg))
(t
(setq keys (plist-put keys key arg)))))
;; collect `interactive' specification
(when (eq (car-safe (car-safe body)) 'interactive)
(setq interactive (cdr-safe (pop body))))
;; transform extended interactive specs
(setq interactive (apply #'evil-interactive-form interactive))
(setq keys (evil-concat-plists keys (cdr-safe interactive))
interactive (car-safe interactive))
;; macro expansion
`(evil-define-command ,operator ,args
,@(when doc `(,doc))
,@keys
:keep-visual t
:suppress-operator t
(interactive
(let* ((evil-operator-range-motion
(when (evil-has-command-property-p ',operator :motion)
;; :motion nil is equivalent to :motion undefined
(or (evil-get-command-property ',operator :motion)
#'undefined)))
(evil-operator-range-type
(evil-get-command-property ',operator :type))
(orig (point))
evil-operator-range-beginning
evil-operator-range-end
evil-inhibit-operator)
(setq evil-inhibit-operator-value nil
evil-this-operator this-command)
(prog1 ,interactive
(setq orig (point)
evil-inhibit-operator-value evil-inhibit-operator)
(if ,visual
(when (evil-visual-state-p)
(evil-visual-expand-region))
(when (or (evil-visual-state-p) (region-active-p))
(setq deactivate-mark t)))
(cond
((evil-visual-state-p)
(evil-visual-rotate 'upper-left))
((evil-get-command-property ',operator :move-point)
(goto-char (or evil-operator-range-beginning orig)))
(t
(goto-char orig))))))
(unwind-protect
(let ((evil-inhibit-operator evil-inhibit-operator-value))
(unless (and evil-inhibit-operator
(called-interactively-p 'any))
,@body))
(setq evil-inhibit-operator-value nil)))))
;; this is used in the `interactive' specification of an operator command
(defun evil-operator-range (&optional return-type)
"Read a motion from the keyboard and return its buffer positions.
The return value is a list (BEG END), or (BEG END TYPE) if
RETURN-TYPE is non-nil."
(let* ((evil-ex-p (and (not (minibufferp)) (evil-ex-p)))
(motion (or evil-operator-range-motion
(when evil-ex-p 'evil-line)))
(type evil-operator-range-type)
(range (evil-range (point) (point)))
command count)
(setq evil-this-type-modified nil)
(evil-save-echo-area
(cond
;; Ex mode
((and evil-ex-p evil-ex-range)
(setq range evil-ex-range))
;; Visual selection
((and (not evil-ex-p) (evil-visual-state-p))
(setq range (evil-visual-range)))
;; active region
((and (not evil-ex-p) (region-active-p))
(setq range (evil-range (region-beginning)
(region-end)
(or evil-this-type 'exclusive))))
(t
;; motion
(evil-save-state
(unless motion
(evil-change-state 'operator)
;; Make linewise operator shortcuts. E.g., "d" yields the
;; shortcut "dd", and "g?" yields shortcuts "g??" and "g?g?".
(let ((keys (nth 2 (evil-extract-count (this-command-keys)))))
(setq keys (listify-key-sequence keys))
(dotimes (var (length keys))
(define-key evil-operator-shortcut-map
(vconcat (nthcdr var keys)) 'evil-line-or-visual-line)))
;; read motion from keyboard
(setq command (evil-read-motion motion)
motion (nth 0 command)
count (nth 1 command)
type (or type (nth 2 command))))
(cond
((eq motion #'undefined)
(setq range (if return-type '(nil nil nil) '(nil nil))
motion nil))
((or (null motion) ; keyboard-quit
(evil-get-command-property motion :suppress-operator))
(when (fboundp 'evil-repeat-abort)
(evil-repeat-abort))
(setq quit-flag t
motion nil))
(evil-repeat-count
(setq count evil-repeat-count
;; only the first operator's count is overwritten
evil-repeat-count nil))
((or count current-prefix-arg)
;; multiply operator count and motion count together
(setq count
(* (prefix-numeric-value count)
(prefix-numeric-value current-prefix-arg)))))
(when motion
(let ((evil-state 'operator)
mark-active)
;; calculate motion range
(setq range (evil-motion-range
motion
count
type))))
;; update global variables
(setq evil-this-motion motion
evil-this-motion-count count
type (evil-type range type)
evil-this-type type))))
(when (evil-range-p range)
(unless (or (null type) (eq (evil-type range) type))
(evil-contract-range range)
(evil-set-type range type)
(evil-expand-range range))
(evil-set-range-properties range nil)
(unless return-type
(evil-set-type range nil))
(setq evil-operator-range-beginning (evil-range-beginning range)
evil-operator-range-end (evil-range-end range)
evil-operator-range-type (evil-type range)))
range)))
(defmacro evil-define-type (type doc &rest body)
"Define type TYPE.
DOC is a general description and shows up in all docstrings.
Optional keyword arguments:
- `:expand' - expansion function. This function should accept two
positions in the current buffer, BEG and END,and return a pair of
expanded buffer positions.
- `:contract' - the opposite of `:expand'. Optional.
- `:one-to-one' - non-nil if expansion is one-to-one. This means that
`:expand' followed by `:contract' always return the original range.
- `:normalize' - normalization function. This function should accept
two unexpanded positions and adjust them before expansion. May be
used to deal with buffer boundaries.
- `:string' - description function. Takes two buffer positions and
returns a human-readable string. For example \"2 lines\"
If further keywords and functions are specified, they are assumed to
be transformations on buffer positions, like `:expand' and `:contract'.
\(fn TYPE DOC [[KEY FUNC]...])"
(declare (indent defun)
(doc-string 2)
(debug (&define name
[&optional stringp]
[&rest [keywordp function-form]])))
(let (args defun-forms func key name plist string sym val)
;; standard values
(setq plist (plist-put plist :one-to-one t))
;; keywords
(while (keywordp (car-safe body))
(setq key (pop body)
val (pop body))
(if (plist-member plist key) ; not a function
(setq plist (plist-put plist key val))
(setq func val
sym (intern (replace-regexp-in-string
"^:" "" (symbol-name key)))
name (intern (format "evil-%s-%s" type sym))
args (car (cdr-safe func))
string (car (cdr (cdr-safe func)))
string (if (stringp string)
(format "%s\n\n" string) "")
plist (plist-put plist key `',name))
(push
(cond
((eq key :string)
`(defun ,name (beg end &rest properties)
,(format "Return size of %s from BEG to END \
with PROPERTIES.\n\n%s%s" type string doc)
(let ((beg (evil-normalize-position beg))
(end (evil-normalize-position end))
(type ',type)
plist range)
(when (and beg end)
(save-excursion
(evil-sort beg end)
(unless (plist-get properties :expanded)
(setq range (apply #'evil-expand
beg end type properties)
beg (evil-range-beginning range)
end (evil-range-end range)
type (evil-type range type)
plist (evil-range-properties range))
(setq properties
(evil-concat-plists properties plist)))
(or (apply #',func beg end
(when ,(> (length args) 2)
properties))
""))))))
(t
`(defun ,name (beg end &rest properties)
,(format "Perform %s transformation on %s from BEG to END \
with PROPERTIES.\n\n%s%s" sym type string doc)
(let ((beg (evil-normalize-position beg))
(end (evil-normalize-position end))
(type ',type)
plist range)
(when (and beg end)
(save-excursion
(evil-sort beg end)
(when (memq ,key '(:expand :contract))
(setq properties
(plist-put properties
:expanded
,(eq key :expand))))
(setq range (or (apply #',func beg end
(when ,(> (length args) 2)
properties))
(apply #'evil-range
beg end type properties))
beg (evil-range-beginning range)
end (evil-range-end range)
type (evil-type range type)
plist (evil-range-properties range))
(setq properties
(evil-concat-plists properties plist))
(apply #'evil-range beg end type properties)))))))
defun-forms)))
;; :one-to-one requires both or neither of :expand and :contract
(when (plist-get plist :expand)
(setq plist (plist-put plist :one-to-one
(and (plist-get plist :contract)
(plist-get plist :one-to-one)))))
`(progn
(evil-put-property 'evil-type-properties ',type ,@plist)
,@defun-forms
',type)))
(defmacro evil-define-interactive-code (code &rest body)
"Define an interactive code.
PROMPT, if given, is the remainder of the interactive string
up to the next newline. Command properties may be specified
via KEY-VALUE pairs. BODY should evaluate to a list of values.
\(fn CODE (PROMPT) [[KEY VALUE]...] BODY...)"
(declare (indent defun))
(let* ((args (when (and (> (length body) 1)
(listp (car-safe body)))
(pop body)))
(doc (when (stringp (car-safe body)) (pop body)))
func properties)
(while (keywordp (car-safe body))
(setq properties
(append properties (list (pop body) (pop body)))))
(cond
(args
(setq func `(lambda ,args
,@(when doc `(,doc))
,@body)))
((> (length body) 1)
(setq func `(progn ,@body)))
(t
(setq func (car body))))
`(eval-and-compile
(let* ((code ,code)
(entry (assoc code evil-interactive-alist))
(value (cons ',func ',properties)))
(if entry
(setcdr entry value)
(push (cons code value) evil-interactive-alist))
code))))
;;; Highlighting
(when (fboundp 'font-lock-add-keywords)
(font-lock-add-keywords
'emacs-lisp-mode
;; Match all `evil-define-' forms except `evil-define-key'.
;; (In the interests of speed, this expression is incomplete
;; and does not match all three-letter words.)
'(("(\\(evil-\\(?:ex-\\)?define-\
\\(?:[^ k][^ e][^ y]\\|[-[:word:]]\\{4,\\}\\)\\)\
\\>[ \f\t\n\r\v]*\\(\\(?:\\sw\\|\\s_\\)+\\)?"
(1 font-lock-keyword-face)
(2 font-lock-function-name-face nil t))
("(\\(evil-\\(?:delay\\|narrow\\|signal\\|save\\|with\\(?:out\\)?\\)\
\\(?:-[-[:word:]]+\\)?\\)\\>\[ \f\t\n\r\v]+"
1 font-lock-keyword-face)
("(\\(evil-\\(?:[-[:word:]]\\)*loop\\)\\>[ \f\t\n\r\v]+"
1 font-lock-keyword-face))))
(provide 'evil-macros)
;;; evil-macros.el ends here

Binary file not shown.

View File

@ -0,0 +1,620 @@
;;; evil-maps.el --- Default keymaps -*- lexical-binding: t -*-
;; Author: Vegard Øye <vegard_oye at hotmail.com>
;; Maintainer: Vegard Øye <vegard_oye at hotmail.com>
;; Version: 1.14.0
;;
;; This file is NOT part of GNU Emacs.
;;; License:
;; This file is part of Evil.
;;
;; Evil is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; Evil is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with Evil. If not, see <http://www.gnu.org/licenses/>.
(require 'evil-states)
(require 'evil-ex)
(require 'evil-commands)
(require 'evil-command-window)
(require 'evil-common)
;;; Code:
;;; Normal state
(define-key evil-normal-state-map "a" 'evil-append)
(define-key evil-normal-state-map "A" 'evil-append-line)
(define-key evil-normal-state-map "c" 'evil-change)
(define-key evil-normal-state-map "C" 'evil-change-line)
(define-key evil-normal-state-map "d" 'evil-delete)
(define-key evil-normal-state-map "D" 'evil-delete-line)
(define-key evil-normal-state-map "i" 'evil-insert)
(define-key evil-normal-state-map (kbd "<insert>") 'evil-insert)
(define-key evil-normal-state-map (kbd "<insertchar>") 'evil-insert)
(define-key evil-normal-state-map "I" 'evil-insert-line)
(define-key evil-normal-state-map "J" 'evil-join)
(define-key evil-normal-state-map "m" 'evil-set-marker)
(define-key evil-normal-state-map "o" 'evil-open-below)
(define-key evil-normal-state-map "O" 'evil-open-above)
(define-key evil-normal-state-map "p" 'evil-paste-after)
(define-key evil-normal-state-map "P" 'evil-paste-before)
(define-key evil-normal-state-map "q" 'evil-record-macro)
(define-key evil-normal-state-map "r" 'evil-replace)
(define-key evil-normal-state-map "R" 'evil-replace-state)
(define-key evil-normal-state-map "s" 'evil-substitute)
(define-key evil-normal-state-map "S" 'evil-change-whole-line)
(define-key evil-normal-state-map "x" 'evil-delete-char)
(define-key evil-normal-state-map "X" 'evil-delete-backward-char)
(define-key evil-normal-state-map [deletechar] 'evil-delete-char)
(define-key evil-normal-state-map "y" 'evil-yank)
(define-key evil-normal-state-map "Y" 'evil-yank-line)
(define-key evil-normal-state-map "&" 'evil-ex-repeat-substitute)
(define-key evil-normal-state-map "g&" 'evil-ex-repeat-global-substitute)
(define-key evil-normal-state-map "g8" 'what-cursor-position)
(define-key evil-normal-state-map "ga" 'what-cursor-position)
(define-key evil-normal-state-map "gi" 'evil-insert-resume)
(define-key evil-normal-state-map "gJ" 'evil-join-whitespace)
(define-key evil-normal-state-map "gq" 'evil-fill-and-move)
(define-key evil-normal-state-map "gw" 'evil-fill)
(define-key evil-normal-state-map "gu" 'evil-downcase)
(define-key evil-normal-state-map "gU" 'evil-upcase)
(define-key evil-normal-state-map "gf" 'find-file-at-point)
(define-key evil-normal-state-map "gF" 'evil-find-file-at-point-with-line)
(define-key evil-normal-state-map "gx" 'browse-url-at-point)
(define-key evil-normal-state-map "g?" 'evil-rot13)
(define-key evil-normal-state-map "g~" 'evil-invert-case)
(define-key evil-normal-state-map "zo" 'evil-open-fold)
(define-key evil-normal-state-map "zO" 'evil-open-fold-rec)
(define-key evil-normal-state-map "zc" 'evil-close-fold)
(define-key evil-normal-state-map "za" 'evil-toggle-fold)
(define-key evil-normal-state-map "zr" 'evil-open-folds)
(define-key evil-normal-state-map "zm" 'evil-close-folds)
(define-key evil-normal-state-map "z=" 'ispell-word)
(define-key evil-normal-state-map "\C-n" 'evil-paste-pop-next)
(define-key evil-normal-state-map "\C-p" 'evil-paste-pop)
(define-key evil-normal-state-map "\C-t" 'pop-tag-mark)
(define-key evil-normal-state-map (kbd "C-.") 'evil-repeat-pop)
(define-key evil-normal-state-map (kbd "M-.") 'evil-repeat-pop-next)
(define-key evil-normal-state-map "." 'evil-repeat)
(define-key evil-normal-state-map "@" 'evil-execute-macro)
(define-key evil-normal-state-map "\"" 'evil-use-register)
(define-key evil-normal-state-map "~" 'evil-invert-char)
(define-key evil-normal-state-map "=" 'evil-indent)
(define-key evil-normal-state-map "<" 'evil-shift-left)
(define-key evil-normal-state-map ">" 'evil-shift-right)
(define-key evil-normal-state-map "ZZ" 'evil-save-modified-and-close)
(define-key evil-normal-state-map "ZQ" 'evil-quit)
(define-key evil-normal-state-map (kbd "DEL") 'evil-backward-char)
(define-key evil-normal-state-map [escape] 'evil-force-normal-state)
(define-key evil-normal-state-map [remap cua-paste-pop] 'evil-paste-pop)
(define-key evil-normal-state-map [remap yank-pop] 'evil-paste-pop)
(when (featurep 'tab-bar)
(define-key evil-normal-state-map "gt" 'tab-bar-switch-to-next-tab)
(define-key evil-normal-state-map "gT" 'tab-bar-switch-to-prev-tab))
;; go to last change
(define-key evil-normal-state-map "g;" 'goto-last-change)
(define-key evil-normal-state-map "g," 'goto-last-change-reverse)
;; undo
(define-key evil-normal-state-map "u" 'evil-undo)
(define-key evil-normal-state-map "\C-r" 'evil-redo)
;; window commands
(define-prefix-command 'evil-window-map)
(define-key evil-window-map "b" 'evil-window-bottom-right)
(define-key evil-window-map "c" 'evil-window-delete)
(define-key evil-window-map "h" 'evil-window-left)
(define-key evil-window-map "H" 'evil-window-move-far-left)
(define-key evil-window-map "j" 'evil-window-down)
(define-key evil-window-map "J" 'evil-window-move-very-bottom)
(define-key evil-window-map "k" 'evil-window-up)
(define-key evil-window-map "K" 'evil-window-move-very-top)
(define-key evil-window-map "l" 'evil-window-right)
(define-key evil-window-map "L" 'evil-window-move-far-right)
(define-key evil-window-map "n" 'evil-window-new)
(define-key evil-window-map "o" 'delete-other-windows)
(define-key evil-window-map "p" 'evil-window-mru)
(define-key evil-window-map "q" 'evil-quit)
(define-key evil-window-map "r" 'evil-window-rotate-downwards)
(define-key evil-window-map "R" 'evil-window-rotate-upwards)
(define-key evil-window-map "s" 'evil-window-split)
(define-key evil-window-map "S" 'evil-window-split)
(define-key evil-window-map "t" 'evil-window-top-left)
(define-key evil-window-map "v" 'evil-window-vsplit)
(define-key evil-window-map "w" 'evil-window-next)
(define-key evil-window-map "W" 'evil-window-prev)
(define-key evil-window-map "+" 'evil-window-increase-height)
(define-key evil-window-map "-" 'evil-window-decrease-height)
(define-key evil-window-map "_" 'evil-window-set-height)
(define-key evil-window-map "<" 'evil-window-decrease-width)
(define-key evil-window-map ">" 'evil-window-increase-width)
(define-key evil-window-map "=" 'balance-windows)
(define-key evil-window-map "|" 'evil-window-set-width)
(define-key evil-window-map "\C-b" 'evil-window-bottom-right)
(define-key evil-window-map "\C-c" 'evil-window-delete)
(define-key evil-window-map (kbd "C-S-h") 'evil-window-move-far-left)
(define-key evil-window-map (kbd "C-S-j") 'evil-window-move-very-bottom)
(define-key evil-window-map (kbd "C-S-k") 'evil-window-move-very-top)
(define-key evil-window-map (kbd "C-S-l") 'evil-window-move-far-right)
(define-key evil-window-map "\C-n" 'evil-window-new)
(define-key evil-window-map "\C-o" 'delete-other-windows)
(define-key evil-window-map "\C-p" 'evil-window-mru)
(define-key evil-window-map "\C-r" 'evil-window-rotate-downwards)
(define-key evil-window-map (kbd "C-S-r") 'evil-window-rotate-upwards)
(define-key evil-window-map "\C-s" 'evil-window-split)
(define-key evil-window-map (kbd "C-S-s") 'evil-window-split)
(define-key evil-window-map "\C-t" 'evil-window-top-left)
(define-key evil-window-map "\C-v" 'evil-window-vsplit)
(define-key evil-window-map "\C-w" 'evil-window-next)
(define-key evil-window-map (kbd "C-S-W") 'evil-window-prev)
(define-key evil-window-map "\C-_" 'evil-window-set-height)
(define-key evil-window-map "\C-f" 'ffap-other-window)
;;; Motion state
;; "0" is a special command when called first
(evil-redirect-digit-argument evil-motion-state-map "0" 'evil-beginning-of-line)
(define-key evil-motion-state-map "1" 'digit-argument)
(define-key evil-motion-state-map "2" 'digit-argument)
(define-key evil-motion-state-map "3" 'digit-argument)
(define-key evil-motion-state-map "4" 'digit-argument)
(define-key evil-motion-state-map "5" 'digit-argument)
(define-key evil-motion-state-map "6" 'digit-argument)
(define-key evil-motion-state-map "7" 'digit-argument)
(define-key evil-motion-state-map "8" 'digit-argument)
(define-key evil-motion-state-map "9" 'digit-argument)
(define-key evil-motion-state-map "b" 'evil-backward-word-begin)
(define-key evil-motion-state-map "B" 'evil-backward-WORD-begin)
(define-key evil-motion-state-map "e" 'evil-forward-word-end)
(define-key evil-motion-state-map "E" 'evil-forward-WORD-end)
(define-key evil-motion-state-map "f" 'evil-find-char)
(define-key evil-motion-state-map "F" 'evil-find-char-backward)
(define-key evil-motion-state-map "G" 'evil-goto-line)
(define-key evil-motion-state-map "h" 'evil-backward-char)
(define-key evil-motion-state-map "H" 'evil-window-top)
(define-key evil-motion-state-map "j" 'evil-next-line)
(define-key evil-motion-state-map "k" 'evil-previous-line)
(define-key evil-motion-state-map "l" 'evil-forward-char)
(define-key evil-motion-state-map " " 'evil-forward-char)
(define-key evil-motion-state-map "K" 'evil-lookup)
(define-key evil-motion-state-map "L" 'evil-window-bottom)
(define-key evil-motion-state-map "M" 'evil-window-middle)
(define-key evil-motion-state-map "n" 'evil-search-next)
(define-key evil-motion-state-map "N" 'evil-search-previous)
(define-key evil-motion-state-map "t" 'evil-find-char-to)
(define-key evil-motion-state-map "T" 'evil-find-char-to-backward)
(define-key evil-motion-state-map "w" 'evil-forward-word-begin)
(define-key evil-motion-state-map "W" 'evil-forward-WORD-begin)
(define-key evil-motion-state-map "y" 'evil-yank)
(define-key evil-motion-state-map "Y" 'evil-yank-line)
(define-key evil-motion-state-map "gd" 'evil-goto-definition)
(define-key evil-motion-state-map "ge" 'evil-backward-word-end)
(define-key evil-motion-state-map "gE" 'evil-backward-WORD-end)
(define-key evil-motion-state-map "gg" 'evil-goto-first-line)
(define-key evil-motion-state-map "gj" 'evil-next-visual-line)
(define-key evil-motion-state-map "gk" 'evil-previous-visual-line)
(define-key evil-motion-state-map "g0" 'evil-beginning-of-visual-line)
(define-key evil-motion-state-map "g_" 'evil-last-non-blank)
(define-key evil-motion-state-map "g^" 'evil-first-non-blank-of-visual-line)
(define-key evil-motion-state-map "gm" 'evil-middle-of-visual-line)
(define-key evil-motion-state-map "go" 'evil-goto-char)
(define-key evil-motion-state-map "g$" 'evil-end-of-visual-line)
(define-key evil-motion-state-map "g\C-]" 'evil-jump-to-tag)
(define-key evil-motion-state-map "{" 'evil-backward-paragraph)
(define-key evil-motion-state-map "}" 'evil-forward-paragraph)
(define-key evil-motion-state-map "#" 'evil-search-word-backward)
(define-key evil-motion-state-map "g#" 'evil-search-unbounded-word-backward)
(define-key evil-motion-state-map "$" 'evil-end-of-line)
(define-key evil-motion-state-map [end] 'evil-end-of-line)
(define-key evil-motion-state-map [home] 'evil-beginning-of-line)
(define-key evil-motion-state-map "%" 'evil-jump-item)
(define-key evil-motion-state-map "`" 'evil-goto-mark)
(define-key evil-motion-state-map "'" 'evil-goto-mark-line)
(define-key evil-motion-state-map "(" 'evil-backward-sentence-begin)
(define-key evil-motion-state-map ")" 'evil-forward-sentence-begin)
(define-key evil-motion-state-map "]]" 'evil-forward-section-begin)
(define-key evil-motion-state-map "][" 'evil-forward-section-end)
(define-key evil-motion-state-map "[[" 'evil-backward-section-begin)
(define-key evil-motion-state-map "[]" 'evil-backward-section-end)
(define-key evil-motion-state-map "[(" 'evil-previous-open-paren)
(define-key evil-motion-state-map "])" 'evil-next-close-paren)
(define-key evil-motion-state-map "[{" 'evil-previous-open-brace)
(define-key evil-motion-state-map "]}" 'evil-next-close-brace)
(define-key evil-motion-state-map "]'" 'evil-next-mark-line)
(define-key evil-motion-state-map "]`" 'evil-next-mark)
(define-key evil-motion-state-map "['" 'evil-previous-mark-line)
(define-key evil-motion-state-map "[`" 'evil-previous-mark)
(define-key evil-motion-state-map "]s" 'evil-next-flyspell-error)
(define-key evil-motion-state-map "[s" 'evil-prev-flyspell-error)
(define-key evil-motion-state-map "*" 'evil-search-word-forward)
(define-key evil-motion-state-map "g*" 'evil-search-unbounded-word-forward)
(define-key evil-motion-state-map "," 'evil-repeat-find-char-reverse)
(define-key evil-motion-state-map "/" 'evil-search-forward)
(define-key evil-motion-state-map ";" 'evil-repeat-find-char)
(define-key evil-motion-state-map "?" 'evil-search-backward)
(define-key evil-motion-state-map "|" 'evil-goto-column)
(define-key evil-motion-state-map "^" 'evil-first-non-blank)
(define-key evil-motion-state-map "+" 'evil-next-line-first-non-blank)
(define-key evil-motion-state-map "_" 'evil-next-line-1-first-non-blank)
(define-key evil-motion-state-map "-" 'evil-previous-line-first-non-blank)
(define-key evil-motion-state-map "\C-w" 'evil-window-map)
(define-key evil-motion-state-map (kbd "C-6") 'evil-switch-to-windows-last-buffer)
(define-key evil-motion-state-map "\C-]" 'evil-jump-to-tag)
(define-key evil-motion-state-map (kbd "C-b") 'evil-scroll-page-up)
(define-key evil-motion-state-map (kbd "C-e") 'evil-scroll-line-down)
(define-key evil-motion-state-map (kbd "C-f") 'evil-scroll-page-down)
(define-key evil-motion-state-map (kbd "C-o") 'evil-jump-backward)
(define-key evil-motion-state-map (kbd "C-y") 'evil-scroll-line-up)
(define-key evil-motion-state-map (kbd "RET") 'evil-ret)
(define-key evil-motion-state-map "\\" 'evil-execute-in-emacs-state)
(define-key evil-motion-state-map "z^" 'evil-scroll-top-line-to-bottom)
(define-key evil-motion-state-map "z+" 'evil-scroll-bottom-line-to-top)
(define-key evil-motion-state-map "zt" 'evil-scroll-line-to-top)
;; TODO: z RET has an advanced form taking an count before the RET
;; but this requires again a special state with a single command
;; bound to RET
(define-key evil-motion-state-map (vconcat "z" [return]) "zt^")
(define-key evil-motion-state-map (kbd "z RET") (vconcat "z" [return]))
(define-key evil-motion-state-map "zz" 'evil-scroll-line-to-center)
(define-key evil-motion-state-map "z." "zz^")
(define-key evil-motion-state-map "zb" 'evil-scroll-line-to-bottom)
(define-key evil-motion-state-map "z-" "zb^")
(define-key evil-motion-state-map "v" 'evil-visual-char)
(define-key evil-motion-state-map "V" 'evil-visual-line)
(define-key evil-motion-state-map "\C-v" 'evil-visual-block)
(define-key evil-motion-state-map "gv" 'evil-visual-restore)
(define-key evil-motion-state-map (kbd "C-^") 'evil-buffer)
(define-key evil-motion-state-map [left] 'evil-backward-char)
(define-key evil-motion-state-map [right] 'evil-forward-char)
(define-key evil-motion-state-map [up] 'evil-previous-line)
(define-key evil-motion-state-map [down] 'evil-next-line)
(define-key evil-motion-state-map "zl" 'evil-scroll-column-right)
(define-key evil-motion-state-map [?z right] "zl")
(define-key evil-motion-state-map "zh" 'evil-scroll-column-left)
(define-key evil-motion-state-map [?z left] "zh")
(define-key evil-motion-state-map "zL" 'evil-scroll-right)
(define-key evil-motion-state-map "zH" 'evil-scroll-left)
(define-key evil-motion-state-map
(read-kbd-macro evil-toggle-key) 'evil-emacs-state)
;; text objects
(define-key evil-outer-text-objects-map "w" 'evil-a-word)
(define-key evil-outer-text-objects-map "W" 'evil-a-WORD)
(define-key evil-outer-text-objects-map "s" 'evil-a-sentence)
(define-key evil-outer-text-objects-map "p" 'evil-a-paragraph)
(define-key evil-outer-text-objects-map "b" 'evil-a-paren)
(define-key evil-outer-text-objects-map "(" 'evil-a-paren)
(define-key evil-outer-text-objects-map ")" 'evil-a-paren)
(define-key evil-outer-text-objects-map "[" 'evil-a-bracket)
(define-key evil-outer-text-objects-map "]" 'evil-a-bracket)
(define-key evil-outer-text-objects-map "B" 'evil-a-curly)
(define-key evil-outer-text-objects-map "{" 'evil-a-curly)
(define-key evil-outer-text-objects-map "}" 'evil-a-curly)
(define-key evil-outer-text-objects-map "<" 'evil-an-angle)
(define-key evil-outer-text-objects-map ">" 'evil-an-angle)
(define-key evil-outer-text-objects-map "'" 'evil-a-single-quote)
(define-key evil-outer-text-objects-map "\"" 'evil-a-double-quote)
(define-key evil-outer-text-objects-map "`" 'evil-a-back-quote)
(define-key evil-outer-text-objects-map "t" 'evil-a-tag)
(define-key evil-outer-text-objects-map "o" 'evil-a-symbol)
(define-key evil-inner-text-objects-map "w" 'evil-inner-word)
(define-key evil-inner-text-objects-map "W" 'evil-inner-WORD)
(define-key evil-inner-text-objects-map "s" 'evil-inner-sentence)
(define-key evil-inner-text-objects-map "p" 'evil-inner-paragraph)
(define-key evil-inner-text-objects-map "b" 'evil-inner-paren)
(define-key evil-inner-text-objects-map "(" 'evil-inner-paren)
(define-key evil-inner-text-objects-map ")" 'evil-inner-paren)
(define-key evil-inner-text-objects-map "[" 'evil-inner-bracket)
(define-key evil-inner-text-objects-map "]" 'evil-inner-bracket)
(define-key evil-inner-text-objects-map "B" 'evil-inner-curly)
(define-key evil-inner-text-objects-map "{" 'evil-inner-curly)
(define-key evil-inner-text-objects-map "}" 'evil-inner-curly)
(define-key evil-inner-text-objects-map "<" 'evil-inner-angle)
(define-key evil-inner-text-objects-map ">" 'evil-inner-angle)
(define-key evil-inner-text-objects-map "'" 'evil-inner-single-quote)
(define-key evil-inner-text-objects-map "\"" 'evil-inner-double-quote)
(define-key evil-inner-text-objects-map "`" 'evil-inner-back-quote)
(define-key evil-inner-text-objects-map "t" 'evil-inner-tag)
(define-key evil-inner-text-objects-map "o" 'evil-inner-symbol)
(define-key evil-motion-state-map "gn" 'evil-next-match)
(define-key evil-motion-state-map "gN" 'evil-previous-match)
(when evil-want-C-i-jump
(define-key evil-motion-state-map (kbd "C-i") 'evil-jump-forward))
(when evil-want-C-u-scroll
(define-key evil-motion-state-map (kbd "C-u") 'evil-scroll-up))
(when evil-want-C-d-scroll
(define-key evil-motion-state-map (kbd "C-d") 'evil-scroll-down))
(when evil-want-C-g-bindings
(define-key evil-motion-state-map "g\C-g" 'count-words))
;;; Visual state
(define-key evil-visual-state-map "A" 'evil-append)
(define-key evil-visual-state-map "I" 'evil-insert)
(define-key evil-visual-state-map "o" 'exchange-point-and-mark)
(define-key evil-visual-state-map "O" 'evil-visual-exchange-corners)
(define-key evil-visual-state-map "R" 'evil-change)
(define-key evil-visual-state-map "u" 'evil-downcase)
(define-key evil-visual-state-map "U" 'evil-upcase)
(define-key evil-visual-state-map "z=" 'ispell-word)
(define-key evil-visual-state-map "a" evil-outer-text-objects-map)
(define-key evil-visual-state-map "i" evil-inner-text-objects-map)
(define-key evil-visual-state-map (kbd "<insert>") 'undefined)
(define-key evil-visual-state-map (kbd "<insertchar>") 'undefined)
(define-key evil-visual-state-map [remap evil-repeat] 'undefined)
(define-key evil-visual-state-map [escape] 'evil-exit-visual-state)
(define-key evil-visual-state-map "gf" 'evil-find-file-at-point-visual)
;;; Operator-Pending state
(define-key evil-operator-state-map "a" evil-outer-text-objects-map)
(define-key evil-operator-state-map "i" evil-inner-text-objects-map)
;; (define-key evil-operator-state-map [escape] 'keyboard-quit)
;;; Insert state
(defvar evil-insert-state-bindings
`(("\C-v" . quoted-insert)
("\C-k" . evil-insert-digraph)
("\C-o" . evil-execute-in-normal-state)
("\C-r" . evil-paste-from-register)
("\C-y" . evil-copy-from-above)
("\C-e" . evil-copy-from-below)
("\C-n" . evil-complete-next)
("\C-p" . evil-complete-previous)
("\C-x\C-n" . evil-complete-next-line)
("\C-x\C-p" . evil-complete-previous-line)
("\C-t" . evil-shift-right-line)
("\C-d" . evil-shift-left-line)
("\C-a" . evil-paste-last-insertion)
([remap delete-backward-char] . evil-delete-backward-char-and-join)
,(if evil-want-C-w-delete
'("\C-w" . evil-delete-backward-word)
'("\C-w" . evil-window-map))
,@(when evil-want-C-u-delete
'(("\C-u" . evil-delete-back-to-indentation)))
([mouse-2] . mouse-yank-primary))
"Evil's bindings for insert state (for
`evil-insert-state-map'), excluding <delete>, <escape>, and
`evil-toggle-key'.")
(defun evil-update-insert-state-bindings (&optional _option-name remove force)
"Update bindings in `evil-insert-state-map'.
If no arguments are given add the bindings specified in
`evil-insert-state-bindings'. If REMOVE is non nil, remove only
these bindings. Unless FORCE is non nil, this will not
overwriting existing bindings, which means bindings will not be
added if one already exists for a key and only default bindings
are removed.
Note that <delete>, <escape> and `evil-toggle-key' are not
included in `evil-insert-state-bindings' by default."
(interactive)
(dolist (binding evil-insert-state-bindings)
(cond
((and remove
(or force
;; Only remove if the default binding has not changed
(eq (evil-lookup-key evil-insert-state-map (car binding))
(cdr binding))))
(define-key evil-insert-state-map (car binding) nil))
((and (null remove)
(or force
;; Check to see that nothing is bound here before adding
(not (evil-lookup-key evil-insert-state-map (car binding)))))
(define-key evil-insert-state-map (car binding) (cdr binding))))))
(define-key evil-insert-state-map [delete] 'delete-char)
(define-key evil-insert-state-map [escape] 'evil-normal-state)
(define-key evil-insert-state-map
(read-kbd-macro evil-toggle-key) 'evil-emacs-state)
;;; Replace state
(define-key evil-replace-state-map (kbd "DEL") 'evil-replace-backspace)
(define-key evil-replace-state-map [escape] 'evil-normal-state)
;;; Emacs state
(define-key evil-emacs-state-map
(read-kbd-macro evil-toggle-key) 'evil-exit-emacs-state)
(when evil-want-C-w-in-emacs-state
(define-key evil-emacs-state-map "\C-w" 'evil-window-map))
;;; Mouse
(define-key evil-motion-state-map [down-mouse-1] 'evil-mouse-drag-region)
(define-key evil-visual-state-map [mouse-2] 'evil-exit-visual-and-repeat)
(define-key evil-normal-state-map [mouse-2] 'mouse-yank-primary)
;; Ex
(define-key evil-motion-state-map ":" 'evil-ex)
(define-key evil-motion-state-map "!" 'evil-shell-command)
(evil-ex-define-cmd "e[dit]" 'evil-edit)
(evil-ex-define-cmd "w[rite]" 'evil-write)
(evil-ex-define-cmd "wa[ll]" 'evil-write-all)
(evil-ex-define-cmd "sav[eas]" 'evil-save)
(evil-ex-define-cmd "r[ead]" 'evil-read)
(evil-ex-define-cmd "b[uffer]" 'evil-buffer)
(evil-ex-define-cmd "bn[ext]" 'evil-next-buffer)
(evil-ex-define-cmd "bp[revious]" 'evil-prev-buffer)
(evil-ex-define-cmd "bN[ext]" "bprevious")
(evil-ex-define-cmd "sb[uffer]" 'evil-split-buffer)
(evil-ex-define-cmd "sbn[ext]" 'evil-split-next-buffer)
(evil-ex-define-cmd "sbp[revious]" 'evil-split-prev-buffer)
(evil-ex-define-cmd "sbN[ext]" "sbprevious")
(evil-ex-define-cmd "buffers" 'buffer-menu)
(evil-ex-define-cmd "files" 'evil-show-files)
(evil-ex-define-cmd "ls" "buffers")
(evil-ex-define-cmd "c[hange]" 'evil-change)
(evil-ex-define-cmd "co[py]" 'evil-copy)
(evil-ex-define-cmd "t" "copy")
(evil-ex-define-cmd "m[ove]" 'evil-move)
(evil-ex-define-cmd "d[elete]" 'evil-ex-delete)
(evil-ex-define-cmd "y[ank]" 'evil-ex-yank)
(evil-ex-define-cmd "pu[t]" 'evil-ex-put)
(evil-ex-define-cmd "go[to]" 'evil-goto-char)
(evil-ex-define-cmd "j[oin]" 'evil-ex-join)
(evil-ex-define-cmd "le[ft]" 'evil-align-left)
(evil-ex-define-cmd "ri[ght]" 'evil-align-right)
(evil-ex-define-cmd "ce[nter]" 'evil-align-center)
(evil-ex-define-cmd "sp[lit]" 'evil-window-split)
(evil-ex-define-cmd "vs[plit]" 'evil-window-vsplit)
(evil-ex-define-cmd "new" 'evil-window-new)
(evil-ex-define-cmd "ene[w]" 'evil-buffer-new)
(evil-ex-define-cmd "vne[w]" 'evil-window-vnew)
(evil-ex-define-cmd "clo[se]" 'evil-window-delete)
(evil-ex-define-cmd "on[ly]" 'delete-other-windows)
(evil-ex-define-cmd "q[uit]" 'evil-quit)
(evil-ex-define-cmd "wq" 'evil-save-and-close)
(evil-ex-define-cmd "quita[ll]" 'evil-quit-all)
(evil-ex-define-cmd "qa[ll]" "quitall")
(evil-ex-define-cmd "cq[uit]" 'evil-quit-all-with-error-code)
(evil-ex-define-cmd "wqa[ll]" 'evil-save-and-quit)
(evil-ex-define-cmd "xa[ll]" "wqall")
(evil-ex-define-cmd "x[it]" 'evil-save-modified-and-close)
(evil-ex-define-cmd "exi[t]" 'evil-save-modified-and-close)
(evil-ex-define-cmd "bd[elete]" 'evil-delete-buffer)
(evil-ex-define-cmd "bw[ipeout]" 'evil-delete-buffer)
(evil-ex-define-cmd "g[lobal]" 'evil-ex-global)
(evil-ex-define-cmd "v[global]" 'evil-ex-global-inverted)
(evil-ex-define-cmd "norm[al]" 'evil-ex-normal)
(evil-ex-define-cmd "s[ubstitute]" 'evil-ex-substitute)
(evil-ex-define-cmd "&" 'evil-ex-repeat-substitute)
(evil-ex-define-cmd "&&" 'evil-ex-repeat-substitute-with-flags)
(evil-ex-define-cmd "~" 'evil-ex-repeat-substitute-with-search)
(evil-ex-define-cmd "~&" 'evil-ex-repeat-substitute-with-search-and-flags)
(evil-ex-define-cmd "registers" 'evil-show-registers)
(evil-ex-define-cmd "di[splay]" "registers")
(evil-ex-define-cmd "ma[rk]" 'evil-set-col-0-mark)
(evil-ex-define-cmd "marks" 'evil-show-marks)
(evil-ex-define-cmd "delm[arks]" 'evil-delete-marks)
(evil-ex-define-cmd "ju[mps]" 'evil-show-jumps)
(evil-ex-define-cmd "noh[lsearch]" 'evil-ex-nohighlight)
(evil-ex-define-cmd "f[ile]" 'evil-show-file-info)
(evil-ex-define-cmd "<" 'evil-shift-left)
(evil-ex-define-cmd ">" 'evil-shift-right)
(evil-ex-define-cmd "=" 'evil-ex-line-number)
(evil-ex-define-cmd "!" 'evil-shell-command)
(evil-ex-define-cmd "@:" 'evil-ex-repeat)
(evil-ex-define-cmd "mak[e]" 'evil-make)
(evil-ex-define-cmd "cc" 'evil-goto-error)
(evil-ex-define-cmd "cfir[st]" 'first-error)
(evil-ex-define-cmd "cr[ewind]" 'first-error)
(evil-ex-define-cmd "cn[ext]" 'next-error)
(evil-ex-define-cmd "cp[revious]" 'previous-error)
(evil-ex-define-cmd "set-initial-state" 'evil-ex-set-initial-state)
(evil-ex-define-cmd "show-digraphs" 'evil-ex-show-digraphs)
(evil-ex-define-cmd "sor[t]" 'evil-ex-sort)
(evil-ex-define-cmd "res[ize]" 'evil-ex-resize)
(evil-ex-define-cmd "u[ndo]" 'evil-undo)
(evil-ex-define-cmd "red[o]" 'evil-redo)
(when (featurep 'tab-bar)
(evil-ex-define-cmd "tabnew" 'tab-bar-new-tab)
(evil-ex-define-cmd "tabn[ext]" 'tab-bar-switch-to-next-tab)
(evil-ex-define-cmd "tabp[revious]" 'tab-bar-switch-to-prev-tab))
;; search command line
(define-key evil-ex-search-keymap "\d" #'evil-ex-delete-backward-char)
(define-key evil-ex-search-keymap "\C-b" 'move-beginning-of-line)
(define-key evil-ex-search-keymap "\C-c" 'abort-recursive-edit)
(define-key evil-ex-search-keymap "\C-g" 'abort-recursive-edit)
(define-key evil-ex-search-keymap "\C-k" 'evil-insert-digraph)
(define-key evil-ex-search-keymap "\C-f" 'evil-ex-search-command-window)
(define-key evil-ex-search-keymap "\C-r" 'evil-paste-from-register)
(define-key evil-ex-search-keymap "\C-n" 'next-history-element)
(define-key evil-ex-search-keymap "\C-p" 'previous-history-element)
(define-key evil-ex-search-keymap "\C-u" 'evil-delete-whole-line)
(define-key evil-ex-search-keymap "\C-v" #'quoted-insert)
(define-key evil-ex-search-keymap "\C-w" 'backward-kill-word)
;; ex command line
(define-key evil-ex-completion-map "\d" #'evil-ex-delete-backward-char)
(define-key evil-ex-completion-map "\t" #'evil-ex-completion)
(define-key evil-ex-completion-map [tab] #'evil-ex-completion)
(define-key evil-ex-completion-map [remap completion-at-point] #'evil-ex-completion)
(define-key evil-ex-completion-map "\C-a" 'evil-ex-completion)
(define-key evil-ex-completion-map "\C-b" 'move-beginning-of-line)
(define-key evil-ex-completion-map "\C-c" 'abort-recursive-edit)
(define-key evil-ex-completion-map "\C-d" 'evil-ex-completion)
(define-key evil-ex-completion-map "\C-f" 'evil-ex-command-window)
(define-key evil-ex-completion-map "\C-g" 'abort-recursive-edit)
(define-key evil-ex-completion-map "\C-k" 'evil-insert-digraph)
(define-key evil-ex-completion-map "\C-l" 'evil-ex-completion)
(define-key evil-ex-completion-map "\C-p" #'previous-complete-history-element)
(define-key evil-ex-completion-map "\C-r" 'evil-paste-from-register)
(define-key evil-ex-completion-map "\C-n" #'next-complete-history-element)
(define-key evil-ex-completion-map "\C-u" 'evil-delete-whole-line)
(define-key evil-ex-completion-map "\C-v" #'quoted-insert)
(define-key evil-ex-completion-map "\C-w" 'backward-kill-word)
(define-key evil-ex-completion-map [escape] 'abort-recursive-edit)
(define-key evil-ex-completion-map [S-left] 'backward-word)
(define-key evil-ex-completion-map [S-right] 'forward-word)
(define-key evil-ex-completion-map [up] 'previous-complete-history-element)
(define-key evil-ex-completion-map [down] 'next-complete-history-element)
(define-key evil-ex-completion-map [prior] 'previous-history-element)
(define-key evil-ex-completion-map [next] 'next-history-element)
(define-key evil-ex-completion-map [return] 'exit-minibuffer)
(define-key evil-ex-completion-map (kbd "RET") 'exit-minibuffer)
;; eval prompt (the `=' register)
(define-key evil-eval-map "\C-b" 'move-beginning-of-line)
(define-key evil-eval-map "\C-c" 'abort-recursive-edit)
(define-key evil-eval-map "\C-g" 'abort-recursive-edit)
(define-key evil-eval-map "\C-k" 'evil-insert-digraph)
(define-key evil-eval-map "\C-p" #'previous-complete-history-element)
(define-key evil-eval-map "\C-r" 'evil-paste-from-register)
(define-key evil-eval-map "\C-n" #'next-complete-history-element)
(define-key evil-eval-map "\C-u" 'evil-delete-whole-line)
(define-key evil-eval-map "\C-v" #'quoted-insert)
(define-key evil-eval-map "\C-w" 'backward-kill-word)
(define-key evil-eval-map [escape] 'abort-recursive-edit)
(define-key evil-eval-map [S-left] 'backward-word)
(define-key evil-eval-map [S-right] 'forward-word)
(define-key evil-eval-map [up] 'previous-complete-history-element)
(define-key evil-eval-map [down] 'next-complete-history-element)
(define-key evil-eval-map [prior] 'previous-history-element)
(define-key evil-eval-map [next] 'next-history-element)
(define-key evil-eval-map [return] 'exit-minibuffer)
(define-key evil-eval-map (kbd "RET") 'exit-minibuffer)
;; evil-read-key
(define-key evil-read-key-map (kbd "ESC") #'keyboard-quit)
(define-key evil-read-key-map (kbd "C-]") #'keyboard-quit)
(define-key evil-read-key-map (kbd "C-g") #'keyboard-quit)
(define-key evil-read-key-map (kbd "C-q") #'evil-read-quoted-char)
(define-key evil-read-key-map (kbd "C-v") #'evil-read-quoted-char)
(define-key evil-read-key-map (kbd "C-k") #'evil-read-digraph-char)
(define-key evil-read-key-map "\r" "\n")
;; command line window
(evil-define-key 'normal
evil-command-window-mode-map (kbd "RET") 'evil-command-window-execute)
(evil-define-key 'insert
evil-command-window-mode-map (kbd "RET") 'evil-command-window-execute)
(provide 'evil-maps)
;;; evil-maps.el ends here

Binary file not shown.

View File

@ -0,0 +1,10 @@
(define-package "evil" "20210411.2050" "Extensible Vi layer for Emacs."
'((emacs "24.1")
(goto-chg "1.6")
(cl-lib "0.5"))
:commit "d998a8195e404b01e2ea62a455c3dec74d0823c3" :keywords
'("emulation" "vim")
:url "https://github.com/emacs-evil/evil")
;; Local Variables:
;; no-byte-compile: t
;; End:

View File

@ -0,0 +1,641 @@
;;; evil-repeat.el --- Repeat system -*- lexical-binding: t -*-
;; Author: Frank Fischer <frank.fischer at mathematik.tu-chemnitz.de>
;; Maintainer: Vegard Øye <vegard_oye at hotmail.com>
;; Version: 1.14.0
;;
;; This file is NOT part of GNU Emacs.
;;; License:
;; This file is part of Evil.
;;
;; Evil is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; Evil is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with Evil. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; A repeat begins when leaving Normal state; it ends when re-entering
;; Normal state. The diagram below shows possible routes between
;; Normal state (N), Insert state (I), Visual state (V),
;; Operator-Pending state (O) and Replace state (R). (Emacs state
;; is an exception: nothing is repeated in that state.)
;; ___
;; / \
;; | R |
;; \___/
;; ^ |
;; | |
;; ___ |___V ___
;; / \ <------- / \ -------> / \
;; | V | | N | | O |
;; \___/ -------> \___/ <------- \___/
;; | | ^ |
;; | | | |
;; | V___| |
;; | / \ |
;; +--------> | I | <--------+
;; \___/
;;
;; The recording of a repeat is started in one of two cases: Either a
;; command is about being executed (in pre-command-hook) or normal
;; state is exited. The recording is stopped whenever a command has
;; being completed and evil is in normal state afterwards. Therefore,
;; a non-inserting command in normal-state is recorded as a single
;; repeat unit. In contrast, if the command leaves normal state and
;; starts insert-state, all commands that are executed until
;; insert-state is left and normal state is reactivated are recorded
;; together in one repeat unit. In other words, a repeat unit consists
;; of all commands that are executed starting and ending in normal
;; state.
;;
;; Not all commands are recorded. There are several commands that are
;; completely ignored and other commands that even abort the currently
;; active recording, e.g., commands that change the current buffer.
;;
;; During recording the repeat information is appended to the variable
;; `evil-repeat-info', which is cleared when the recording
;; starts. This accumulated repeat information is put into the
;; `evil-repeat-ring' when the recording is finished. The dot command,
;; `\[evil-repeat]' (`evil-repeat') replays the most recent entry in
;; the ring, preceeding repeats can be replayed using
;; `\[evil-repeat-pop]' (`evil-repeat-pop').
;;
;; Repeat information can be stored in almost arbitrary form. How the
;; repeat information for each single command is recored is determined
;; by the :repeat property of the command. This property has the
;; following interpretation:
;;
;; t record commands by storing the key-sequence that invoked it
;; nil ignore this command completely
;; ignore synonym to nil
;; motion command is recorded by storing the key-sequence but only in
;; insert state, otherwise it is ignored.
;; abort stop recording of repeat information immediately
;; change record commands by storing buffer changes
;; SYMBOL if SYMBOL is contained as key in `evil-repeat-types'
;; call the corresponding (function-)value, otherwise
;; call the function associated with SYMBOL. In both
;; cases the function should take exactly one argument
;; which is either 'pre or 'post depending on whether
;; the function is called before or after the execution
;; of the command.
;;
;; Therefore, using a certain SYMBOL one can write specific repeation
;; functions for each command.
;;
;; Each value of ring `evil-repeat-info', i.e., each single repeat
;; information must be one of the following two possibilities:
;; If element is a sequence, it is regarded as a key-sequence to
;; be repeated. Otherwise the element must be a list
;; (FUNCTION PARAMS ...) which will be called using
;; (apply FUNCTION PARAMS) whenever this repeat is being executed.
;;
;; A user supplied repeat function can use the functions
;; `evil-record-repeat' to append further repeat-information of the
;; form described above to `evil-repeat-info'. See the implementation
;; of `evil-repeat-keystrokes' and `evil-repeat-changes' for examples.
;; Those functions are called in different situations before and after
;; the execution of a command. Each function should take one argument
;; which can be either 'pre, 'post, 'pre-operator or 'post-operator
;; specifying when the repeat function has been called. If the command
;; is a usual command the function is called with 'pre before the
;; command is executed and with 'post after the command has been
;; executed.
;;
;; The repeat information is executed with `evil-execute-repeat-info',
;; which passes key-sequence elements to `execute-kbd-macro' and
;; executes other elements as defined above. A special version is
;; `evil-execute-repeat-info-with-count'. This function works as
;; `evil-execute-repeat-info', but replaces the count of the first
;; command. This is done by parsing the key-sequence, ignoring all
;; calls to `digit-prefix-argument' and `negative-argument', and
;; prepending the count as a string to the vector of the remaining
;; key-sequence.
(require 'evil-states)
;;; Code:
(declare-function evil-visual-state-p "evil-visual")
(declare-function evil-visual-range "evil-visual")
(declare-function evil-visual-char "evil-visual")
(declare-function evil-visual-line "evil-visual")
(declare-function evil-visual-block "evil-visual")
(defmacro evil-without-repeat (&rest body)
(declare (indent defun)
(debug t))
`(let ((pre-command-hook (remq 'evil-repeat-pre-hook pre-command-hook))
(post-command-hook (remq 'evil-repeat-post-hook post-command-hook)))
,@body
(evil-repeat-abort)))
(defsubst evil-repeat-recording-p ()
"Returns non-nil iff a recording is in progress."
(eq evil-recording-repeat t))
(defun evil-repeat-start ()
"Start recording a new repeat into `evil-repeat-info'."
(evil-repeat-reset t)
(evil-repeat-record-buffer)
(when (evil-visual-state-p)
(let* ((range (evil-visual-range))
(beg (evil-range-beginning range))
(end (1- (evil-range-end range)))
(nfwdlines (evil-count-lines beg end)))
(evil-repeat-record
(cond
((eq evil-visual-selection 'char)
(list #'evil-repeat-visual-char
nfwdlines
(- end
(if (zerop nfwdlines)
beg
(save-excursion
(goto-char end)
(line-beginning-position))))))
((eq evil-visual-selection 'line)
(list #'evil-repeat-visual-line nfwdlines))
((eq evil-visual-selection 'block)
(list #'evil-repeat-visual-block
nfwdlines
(abs (- (evil-column beg) (evil-column end))))))))))
(defun evil-repeat-stop ()
"Stop recording a repeat.
Update `evil-repeat-ring' with the accumulated changes
in `evil-repeat-info' and clear variables."
(unwind-protect
(when (evil-repeat-recording-p)
(setq evil-repeat-info
(evil-normalize-repeat-info evil-repeat-info))
(when (and evil-repeat-info evil-repeat-ring)
(ring-insert evil-repeat-ring evil-repeat-info)))
(evil-repeat-reset nil)))
(defun evil-repeat-abort ()
"Abort current repeation."
(evil-repeat-reset 'abort))
(defun evil-repeat-reset (flag)
"Clear all repeat recording variables.
Set `evil-recording-repeat' to FLAG."
(setq evil-recording-repeat flag
evil-repeat-info nil
evil-repeat-buffer nil))
(defsubst evil-repeat-record-position (&optional pos)
"Set `evil-repeat-pos' to POS or point."
(setq evil-repeat-pos (or pos (point))))
(defun evil-repeat-record-buffer ()
"Set `evil-repeat-buffer' to the current buffer."
(unless (minibufferp)
(setq evil-repeat-buffer (current-buffer))))
(defmacro evil-save-repeat-info (&rest body)
"Execute BODY, protecting the values of repeat variables."
(declare (indent defun)
(debug t))
`(let (evil-repeat-ring
evil-recording-repeat
evil-recording-current-command
evil-repeat-info
evil-repeat-changes
evil-repeat-pos
evil-repeat-keys
evil-repeat-buffer
this-command
last-command)
,@body))
(defun evil-repeat-different-buffer-p (&optional strict)
"Whether the buffer has changed in a repeat.
If STRICT is non-nil, returns t if the previous buffer
is unknown; otherwise returns t only if the previous
buffer is known and different from the current buffer."
(and (or (buffer-live-p evil-repeat-buffer) strict)
(not (minibufferp))
(not (eq (current-buffer) evil-repeat-buffer))))
(defun evil-repeat-type (command &optional default)
"Return the :repeat property of COMMAND.
If COMMAND doesn't have this property, return DEFAULT."
(when (functionp command) ; ignore keyboard macros
(let* ((type (evil-get-command-property command :repeat default))
(repeat-type (assq type evil-repeat-types)))
(if repeat-type (cdr repeat-type) type))))
(defun evil-repeat-force-abort-p (repeat-type)
"Returns non-nil iff the current command should abort the recording of repeat information."
(or (evil-repeat-different-buffer-p) ; ... buffer changed
(eq repeat-type 'abort) ; ... explicitely forced
(eq evil-recording-repeat 'abort) ; ... already aborted
(evil-emacs-state-p) ; ... in Emacs state
(and (evil-mouse-events-p (this-command-keys)) ; ... mouse events
(eq repeat-type nil))
(minibufferp))) ; ... minibuffer activated
(defun evil-repeat-record (info)
"Add INFO to the end of `evil-repeat-info'."
(when (evil-repeat-recording-p)
(setq evil-repeat-info (nconc evil-repeat-info (list info)))))
;; called from `evil-normal-state-exit-hook'
(defun evil-repeat-start-hook ()
"Record a new repeat when exiting Normal state.
Does not record in Emacs state or if the current command
has :repeat nil."
(when (and (eq (evil-repeat-type this-command t) t)
(not (evil-emacs-state-p)))
(evil-repeat-start)))
;; called from `pre-command-hook'
(defun evil-repeat-pre-hook ()
"Prepare the current command for recording the repeation."
(when evil-local-mode
(let ((repeat-type (evil-repeat-type this-command t)))
(cond
;; abort the repeat
((evil-repeat-force-abort-p repeat-type)
;; We mark the current record as being aborted, because there
;; may be further pre-hooks following before the post-hook is
;; called.
(evil-repeat-abort))
;; ignore those commands completely
((or (null repeat-type)
(evil-mouse-events-p (this-command-keys))))
;; record command
(t
;; In normal-state or visual state, each command is a single
;; repeation, therefore start a new repeation.
(when (or (evil-normal-state-p)
(evil-visual-state-p))
(evil-repeat-start))
(setq evil-recording-current-command t)
(funcall repeat-type 'pre))))))
(put 'evil-repeat-pre-hook 'permanent-local-hook t)
;; called from `post-command-hook'
(defun evil-repeat-post-hook ()
"Finish recording of repeat-information for the current-command."
(when (and evil-local-mode evil-recording-repeat)
(let ((repeat-type (evil-repeat-type this-command t)))
(cond
;; abort the repeat
((evil-repeat-force-abort-p repeat-type)
;; The command has been aborted but is complete, so just reset
;; the recording state.
(evil-repeat-reset nil))
;; ignore if command should not be recorded or the current
;; command is not being recorded
((or (null repeat-type)
(not evil-recording-current-command)))
;; record command
(t
(funcall repeat-type 'post)
;; In normal state, the repeat sequence is complete, so record it.
(when (evil-normal-state-p)
(evil-repeat-stop)))))
;; done with recording the current command
(setq evil-recording-current-command nil)))
(put 'evil-repeat-post-hook 'permanent-local-hook t)
(defun evil-clear-command-keys ()
"Clear `this-command-keys' and all information about the current command keys.
Calling this function prevents further recording of the keys that
invoked the current command"
(clear-this-command-keys t)
(setq evil-repeat-keys ""))
(defun evil-this-command-keys (&optional post-cmd)
"Version of `this-command-keys' with finer control over prefix args."
(let ((arg (if post-cmd current-prefix-arg prefix-arg)))
(vconcat
(when (and (numberp arg)
;; Only add prefix if no repeat info recorded yet
(null evil-repeat-info))
(string-to-vector (number-to-string arg)))
(this-single-command-keys))))
(defun evil-repeat-keystrokes (flag)
"Repeation recording function for commands that are repeated by keystrokes."
(cond
((eq flag 'pre)
(when evil-this-register
(evil-repeat-record
`(set evil-this-register ,evil-this-register)))
(setq evil-repeat-keys (evil-this-command-keys)))
((eq flag 'post)
(evil-repeat-record (if (zerop (length (evil-this-command-keys t)))
evil-repeat-keys
(evil-this-command-keys t)))
;; erase commands keys to prevent double recording
(evil-clear-command-keys))))
(defun evil-repeat-motion (flag)
"Repeation for motions. Motions are recorded by keystroke but only in insert state."
(when (memq evil-state '(insert replace))
(evil-repeat-keystrokes flag)))
(defun evil-repeat-changes (flag)
"Repeation recording function for commands that are repeated by buffer changes."
(cond
((eq flag 'pre)
(add-hook 'after-change-functions #'evil-repeat-change-hook nil t)
(evil-repeat-start-record-changes))
((eq flag 'post)
(remove-hook 'after-change-functions #'evil-repeat-change-hook t)
(evil-repeat-finish-record-changes))))
;; called from the `after-change-functions' hook
(defun evil-repeat-change-hook (beg end length)
"Record change information for current command."
(let ((repeat-type (evil-repeat-type this-command t)))
(when (and (evil-repeat-recording-p)
(eq repeat-type 'evil-repeat-changes)
(not (evil-emacs-state-p))
(not (evil-repeat-different-buffer-p t))
evil-state)
(unless (evil-repeat-recording-p)
(evil-repeat-start))
(evil-repeat-record-change (- beg evil-repeat-pos)
(buffer-substring beg end)
length))))
(put 'evil-repeat-change-hook 'permanent-local-hook t)
(defun evil-repeat-record-change (relpos ins ndel)
"Record the current buffer changes during a repeat.
If CHANGE is specified, it is added to `evil-repeat-changes'."
(when (evil-repeat-recording-p)
(setq evil-repeat-changes
(nconc evil-repeat-changes (list (list relpos ins ndel))))))
(defun evil-repeat-start-record-changes ()
"Starts the recording of a new set of buffer changes."
(setq evil-repeat-changes nil)
(evil-repeat-record-position))
(defun evil-repeat-finish-record-changes ()
"Finishes the recording of buffer changes and records them as repeat."
(when (evil-repeat-recording-p)
(evil-repeat-record `(evil-execute-change
,evil-repeat-changes
,(- (point) evil-repeat-pos)))
(setq evil-repeat-changes nil)))
(defun evil-repeat-insert-at-point (flag)
"Repeation recording function for commands that insert text in region.
This records text insertion when a command inserts some text in a
buffer between (point) and (mark)."
(cond
((eq flag 'pre)
(add-hook 'after-change-functions #'evil-repeat-insert-at-point-hook nil t))
((eq flag 'post)
(remove-hook 'after-change-functions #'evil-repeat-insert-at-point-hook t))))
(defun evil-repeat-insert-at-point-hook (beg end _length)
(let ((repeat-type (evil-repeat-type this-command t)))
(when (and (evil-repeat-recording-p)
(eq repeat-type 'evil-repeat-insert-at-point)
(not (evil-emacs-state-p))
(not (evil-repeat-different-buffer-p t))
evil-state)
(setq evil-repeat-pos beg)
(evil-repeat-record (list 'insert (buffer-substring beg end))))))
(put 'evil-repeat-insert-at-point-hook 'permanent-local-hook t)
(defun evil-normalize-repeat-info (repeat-info)
"Concatenate consecutive arrays in REPEAT-INFO.
Returns a single array."
(let* ((result (cons nil nil))
(result-last result)
cur cur-last)
(dolist (rep repeat-info)
(cond
((null rep))
((arrayp rep)
(setq rep (listify-key-sequence rep))
(cond
(cur
(setcdr cur-last (cons rep nil))
(setq cur-last (cdr cur-last)))
(t
(setq cur (cons rep nil))
(setq cur-last cur))))
(t
(when cur
(setcdr result-last (cons (apply #'vconcat cur) nil))
(setq result-last (cdr result-last))
(setq cur nil))
(setcdr result-last (cons rep nil))
(setq result-last (cdr result-last)))))
(when cur
(setcdr result-last (cons (apply #'vconcat cur) nil)))
(cdr result)))
(defun evil-repeat-visual-char (nfwdlines nfwdchars)
"Restores a character visual selection.
If the selection is in a single line, the restored visual
selection covers the same number of characters. If the selection
covers several lines, the restored selection covers the same
number of lines and the same number of characters in the last
line as the original selection."
(evil-visual-char)
(when (> nfwdlines 0)
(forward-line nfwdlines))
(forward-char nfwdchars))
(defun evil-repeat-visual-line (nfwdlines)
"Restores a character visual selection.
If the selection is in a single line, the restored visual
selection covers the same number of characters. If the selection
covers several lines, the restored selection covers the same
number of lines and the same number of characters in the last
line as the original selection."
(evil-visual-line)
(forward-line nfwdlines))
(defun evil-repeat-visual-block (nfwdlines nfwdchars)
"Restores a character visual selection.
If the selection is in a single line, the restored visual
selection covers the same number of characters. If the selection
covers several lines, the restored selection covers the same
number of lines and the same number of characters in the last
line as the original selection."
(evil-visual-block)
(let ((col (current-column)))
(forward-line nfwdlines)
(move-to-column (+ col nfwdchars) t)))
(defun evil-execute-change (changes rel-point)
"Executes as list of changes.
CHANGES is a list of triples (REL-BEG INSERT-TEXT NDEL).
REL-BEG is the relative position (to point) where the change
takes place. INSERT-TEXT is the text to be inserted at that
position and NDEL the number of characters to be deleted at that
position before insertion.
REL-POINT is the relative position to point before the changed
where point should be placed after all changes."
(evil-save-repeat-info
(let ((point (point)))
(dolist (change changes)
(goto-char (+ point (nth 0 change)))
(delete-char (nth 2 change))
(insert (nth 1 change)))
(goto-char (+ point rel-point)))))
(defun evil-execute-repeat-info (repeat-info)
"Executes a repeat-information REPEAT-INFO."
(evil-save-repeat-info
(dolist (rep repeat-info)
(cond
((or (arrayp rep) (stringp rep))
(let ((input-method current-input-method)
(evil-input-method nil))
(deactivate-input-method)
(unwind-protect
(execute-kbd-macro rep)
(activate-input-method input-method))))
((consp rep)
(when (and (= 3 (length rep))
(eq (nth 0 rep) 'set)
(eq (nth 1 rep) 'evil-this-register)
(>= (nth 2 rep) ?0)
(< (nth 2 rep) ?9))
(setcar (nthcdr 2 rep) (1+ (nth 2 rep))))
(apply (car rep) (cdr rep)))
(t
(error "Unexpected repeat-info: %S" rep))))))
;; TODO: currently we prepend the replacing count before the
;; key-sequence that calls the command. Can we use direct
;; modification of prefix-arg instead? Does it work in
;; conjunction with `execute-kbd-macro'?
(defun evil-execute-repeat-info-with-count (count repeat-info)
"Repeat the repeat-information REPEAT-INFO with the count of
the first command replaced by COUNT. The count is replaced if
and only if COUNT is non-nil."
(evil-save-repeat-info
(cond
;; do nothing (zero repeating)
((and count (zerop count)))
;; replace count
(count
(let ((evil-repeat-count count)
done)
(while (and repeat-info
(arrayp (car repeat-info))
(not done))
(let* ((count-and-cmd (evil-extract-count (pop repeat-info))))
(push (vconcat (number-to-string count)
(nth 2 count-and-cmd)
(nth 3 count-and-cmd))
repeat-info)
(setq done t)))
(evil-execute-repeat-info repeat-info)))
;; repeat with original count
(t
(evil-execute-repeat-info repeat-info)))))
(evil-define-command evil-repeat (count &optional save-point)
"Repeat the last editing command with count replaced by COUNT.
If SAVE-POINT is non-nil, do not move point."
:repeat ignore
:suppress-operator t
(interactive (list current-prefix-arg
(not evil-repeat-move-cursor)))
(cond
((null evil-repeat-ring)
(error "Already executing repeat"))
(save-point
(save-excursion
(evil-repeat count)))
(t
(unwind-protect
(let ((evil-last-find-temp evil-last-find)
(confirm-kill-emacs t)
(kill-buffer-hook
(cons #'(lambda ()
(user-error "Cannot delete buffer in repeat command"))
kill-buffer-hook))
(undo-pointer buffer-undo-list))
(evil-with-single-undo
(setq evil-last-repeat (list (point) count undo-pointer))
(evil-execute-repeat-info-with-count
count (ring-ref evil-repeat-ring 0))
(setq evil-last-find evil-last-find-temp)))
(evil-normal-state)))))
;; TODO: the same issue concering disabled undos as for `evil-paste-pop'
(evil-define-command evil-repeat-pop (count &optional save-point)
"Replace the just repeated command with a previously executed command.
Only allowed after `evil-repeat', `evil-repeat-pop' or
`evil-repeat-pop-next'. Uses the same repeat count that
was used for the first repeat.
The COUNT argument inserts the COUNT-th previous kill.
If COUNT is negative, this is a more recent kill."
:repeat nil
:suppress-operator t
(interactive (list (prefix-numeric-value current-prefix-arg)
(not evil-repeat-move-cursor)))
(cond
((not (and (eq last-command #'evil-repeat)
evil-last-repeat))
(user-error "Previous command was not evil-repeat: %s" last-command))
(save-point
(save-excursion
(evil-repeat-pop count)))
(t
(unless (eq buffer-undo-list (nth 2 evil-last-repeat))
(evil-undo-pop))
(goto-char (car evil-last-repeat))
;; rotate the repeat-ring
(while (> count 0)
(when evil-repeat-ring
(ring-insert-at-beginning evil-repeat-ring
(ring-remove evil-repeat-ring 0)))
(setq count (1- count)))
(while (< count 0)
(when evil-repeat-ring
(ring-insert evil-repeat-ring
(ring-remove evil-repeat-ring)))
(setq count (1+ count)))
(setq this-command #'evil-repeat)
(evil-repeat (cadr evil-last-repeat)))))
(evil-define-command evil-repeat-pop-next (count &optional save-point)
"Same as `evil-repeat-pop', but with negative COUNT."
:repeat nil
:suppress-operator t
(interactive (list (prefix-numeric-value current-prefix-arg)
(not evil-repeat-move-cursor)))
(evil-repeat-pop (- count) save-point))
(defadvice read-key-sequence (before evil activate)
"Record `this-command-keys' before it is reset."
(when (and (evil-repeat-recording-p)
evil-recording-current-command)
(let ((repeat-type (evil-repeat-type this-command t)))
(if (functionp repeat-type)
(funcall repeat-type 'post)))))
(provide 'evil-repeat)
;;; evil-repeat.el ends here

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -0,0 +1,924 @@
;;; evil-states.el --- States -*- lexical-binding: t -*-
;; Author: Vegard Øye <vegard_oye at hotmail.com>
;; Maintainer: Vegard Øye <vegard_oye at hotmail.com>
;; Version: 1.14.0
;;
;; This file is NOT part of GNU Emacs.
;;; License:
;; This file is part of Evil.
;;
;; Evil is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; Evil is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with Evil. If not, see <http://www.gnu.org/licenses/>.
(require 'evil-core)
;;; Code:
;;; Normal state
(evil-define-state normal
"Normal state.
AKA \"Command\" state."
:tag " <N> "
:enable (motion)
:exit-hook (evil-repeat-start-hook)
(cond
((evil-normal-state-p)
(overwrite-mode -1)
(add-hook 'post-command-hook #'evil-normal-post-command nil t))
(t
(remove-hook 'post-command-hook #'evil-normal-post-command t))))
(defun evil-normal-post-command (&optional command)
"Reset command loop variables in Normal state.
Also prevent point from reaching the end of the line.
If the region is activated, enter Visual state."
(unless (or (evil-initializing-p)
(null this-command))
(setq command (or command this-command))
(when (evil-normal-state-p)
(setq evil-this-type nil
evil-this-operator nil
evil-this-motion nil
evil-this-motion-count nil
evil-inhibit-operator nil
evil-inhibit-operator-value nil)
(unless (memq command '(evil-use-register
digit-argument
negative-argument
universal-argument
universal-argument-minus
universal-argument-more
universal-argument-other-key))
(setq evil-this-register nil))
(evil-adjust-cursor))))
(put 'evil-normal-post-command 'permanent-local-hook t)
;;; Insert state
(defun evil-maybe-remove-spaces (&optional do-remove)
"Remove space from newly opened empty line.
This function removes (indentation) spaces that have been
inserted by opening a new empty line. The behavior depends on the
variable `evil-maybe-remove-spaces'. If this variable is nil the
function does nothing. Otherwise the behavior depends on
DO-REMOVE. If DO-REMOVE is non-nil the spaces are
removed. Otherwise `evil-maybe-remove-spaces' is set to nil
unless the last command opened yet another new line.
This function should be added as a post-command-hook to track
commands opening a new line."
(cond
((not evil-maybe-remove-spaces)
(remove-hook 'post-command-hook #'evil-maybe-remove-spaces))
(do-remove
(when (save-excursion
(beginning-of-line)
(looking-at "^\\s-*$"))
(delete-region (line-beginning-position)
(line-end-position)))
(setq evil-maybe-remove-spaces nil)
(remove-hook 'post-command-hook #'evil-maybe-remove-spaces))
((not (memq this-command
'(evil-open-above
evil-open-below
evil-append
evil-append-line
newline
newline-and-indent
indent-and-newline)))
(setq evil-maybe-remove-spaces nil)
(remove-hook 'post-command-hook #'evil-maybe-remove-spaces))))
(evil-define-state insert
"Insert state."
:tag " <I> "
:cursor (bar . 2)
:message "-- INSERT --"
:entry-hook (evil-start-track-last-insertion)
:exit-hook (evil-cleanup-insert-state evil-stop-track-last-insertion)
:input-method t
(cond
((evil-insert-state-p)
(add-hook 'post-command-hook #'evil-maybe-remove-spaces)
(add-hook 'pre-command-hook #'evil-insert-repeat-hook)
(setq evil-maybe-remove-spaces t)
(unless (eq evil-want-fine-undo t)
(evil-start-undo-step)))
(t
(remove-hook 'post-command-hook #'evil-maybe-remove-spaces)
(remove-hook 'pre-command-hook #'evil-insert-repeat-hook)
(evil-maybe-remove-spaces t)
(setq evil-insert-repeat-info evil-repeat-info)
(evil-set-marker ?^ nil t)
(unless (eq evil-want-fine-undo t)
(evil-end-undo-step))
(when (or (evil-normal-state-p evil-next-state)
(evil-motion-state-p evil-next-state))
(evil-move-cursor-back
(and (eolp) (not evil-move-beyond-eol)))))))
(defun evil-insert-repeat-hook ()
"Record insertion keys in `evil-insert-repeat-info'."
(setq evil-insert-repeat-info (last evil-repeat-info))
(remove-hook 'pre-command-hook #'evil-insert-repeat-hook))
(put 'evil-insert-repeat-hook 'permanent-local-hook t)
(defun evil-cleanup-insert-state ()
"Called when Insert state is about to be exited.
Handles the repeat-count of the insertion command."
(when evil-insert-count
(dotimes (_ (1- evil-insert-count))
(when evil-insert-lines
(evil-insert-newline-below)
(when evil-auto-indent
(indent-according-to-mode)))
(when (fboundp 'evil-execute-repeat-info)
(evil-execute-repeat-info
(cdr evil-insert-repeat-info)))))
(when evil-insert-vcount
(let ((buffer-invisibility-spec buffer-invisibility-spec))
;; make all lines hidden by hideshow temporarily visible
(when (listp buffer-invisibility-spec)
(setq buffer-invisibility-spec
(evil-filter-list
#'(lambda (x)
(or (eq x 'hs)
(eq (car-safe x) 'hs)))
buffer-invisibility-spec)))
(let ((line (nth 0 evil-insert-vcount))
(col (nth 1 evil-insert-vcount))
(vcount (nth 2 evil-insert-vcount)))
(save-excursion
(dotimes (v (1- vcount))
(goto-char (point-min))
(forward-line (+ line v))
(when (or (not evil-insert-skip-empty-lines)
(not (integerp col))
(save-excursion
(evil-move-end-of-line)
(>= (current-column) col)))
(if (integerp col)
(move-to-column col t)
(funcall col))
(dotimes (_ (or evil-insert-count 1))
(when (fboundp 'evil-execute-repeat-info)
(evil-execute-repeat-info
(cdr evil-insert-repeat-info)))))))))))
;;; Visual state
;; Visual selections are implemented in terms of types, and are
;; compatible with the Emacs region. This is achieved by "translating"
;; the region to the selected text right before a command is executed.
;; If the command is a motion, the translation is postponed until a
;; non-motion command is invoked (distinguished by the :keep-visual
;; command property).
;;
;; Visual state activates the region, enabling Transient Mark mode if
;; not already enabled. This is only temporay: if Transient Mark mode
;; was disabled before entering Visual state, it is disabled when
;; exiting Visual state. This allows Visual state to harness the
;; "transient" behavior of many commands without overriding the user's
;; preferences in other states.
(defmacro evil-define-visual-selection (selection doc &rest body)
"Define a Visual selection SELECTION.
Creates a command evil-visual-SELECTION for enabling the selection.
DOC is the function's documentation string. The following keywords
may be specified in BODY:
:message STRING Status message when enabling the selection.
:type TYPE Type to use (defaults to SELECTION).
Following the keywords is optional code which is executed each time
the selection is enabled.
\(fn SELECTION DOC [[KEY VAL]...] BODY...)"
(declare (indent defun)
(doc-string 2)
(debug (&define name stringp
[&rest keywordp sexp]
def-body)))
(let* ((name (intern (format "evil-visual-%s" selection)))
(message (intern (format "%s-message" name)))
(tagvar (intern (format "%s-tag" name)))
(type selection)
(tag " <V> ")
arg key string)
;; collect keywords
(while (keywordp (car-safe body))
(setq key (pop body)
arg (pop body))
(cond
((eq key :message)
(setq string arg))
((eq key :type)
(setq type arg))
((eq key :tag)
(setq tag arg))))
;; macro expansion
`(progn
(add-to-list 'evil-visual-alist (cons ',selection ',name))
(defvar ,name ',type ,(format "*%s" doc))
(defvar ,message ,string ,doc)
(defvar ,tagvar ,tag ,doc)
(evil-define-command ,name (&optional mark point type message)
,@(when doc `(,doc))
:keep-visual t
:repeat nil
(interactive
(list nil nil
(if (and (evil-visual-state-p)
(eq evil-visual-selection ',selection))
'exit ,name) t))
(if (eq type 'exit)
(evil-exit-visual-state)
(setq type (or type ,name)
evil-visual-selection ',selection)
(evil-visual-make-region mark point type message)
,@body))
',selection)))
(evil-define-visual-selection char
"Characterwise selection."
:type inclusive
:message "-- VISUAL --"
:tag " <V> ")
(evil-define-visual-selection line
"Linewise selection."
:message "-- VISUAL LINE --"
:tag " <Vl> ")
(evil-define-visual-selection screen-line
"Linewise selection in `visual-line-mode'."
:message "-- SCREEN LINE --"
:tag " <Vs> ")
(evil-define-visual-selection block
"Blockwise selection."
:message "-- VISUAL BLOCK --"
:tag " <Vb> "
(evil-transient-mark -1)
;; refresh the :corner property
(setq evil-visual-properties
(plist-put evil-visual-properties :corner
(evil-visual-block-corner 'upper-left))))
(evil-define-state visual
"Visual state."
:tag 'evil-visual-tag
:enable (motion normal)
:message 'evil-visual-message
(cond
((evil-visual-state-p)
(evil-save-transient-mark-mode)
(setq select-active-regions nil)
(cond
((region-active-p)
(if (< (evil-visual-direction) 0)
(evil-visual-select (region-beginning) (region-end)
evil-visual-char
(evil-visual-direction))
(evil-visual-make-selection (mark t) (point)
evil-visual-char))
(evil-visual-highlight))
(t
(evil-visual-make-region (point) (point) evil-visual-char)))
(add-hook 'pre-command-hook #'evil-visual-pre-command nil t)
(add-hook 'post-command-hook #'evil-visual-post-command nil t)
(add-hook 'deactivate-mark-hook #'evil-visual-deactivate-hook nil t))
(t
;; Postpone deactivation of region if next state is Insert.
;; This gives certain insertion commands (auto-pairing characters,
;; for example) an opportunity to access the region.
(if (and (eq evil-next-state 'insert)
(eq evil-visual-selection 'char))
(add-hook 'evil-normal-state-entry-hook
#'evil-visual-deactivate-hook nil t)
(evil-visual-deactivate-hook))
(setq evil-visual-region-expanded nil)
(remove-hook 'pre-command-hook #'evil-visual-pre-command t)
(remove-hook 'post-command-hook #'evil-visual-post-command t)
(remove-hook 'deactivate-mark-hook #'evil-visual-deactivate-hook t)
(evil-visual-highlight -1))))
(defun evil-visual-pre-command (&optional command)
"Run before each COMMAND in Visual state.
Expand the region to the selection unless COMMAND is a motion."
(when (evil-visual-state-p)
(setq command (or command this-command))
(when evil-visual-x-select-timer
(cancel-timer evil-visual-x-select-timer))
(unless (evil-get-command-property command :keep-visual)
(evil-visual-update-x-selection)
(evil-visual-expand-region
;; exclude final newline from linewise selection
;; unless the command has real need of it
(and (eq (evil-visual-type) 'line)
(evil-get-command-property command :exclude-newline))))))
(put 'evil-visual-pre-command 'permanent-local-hook t)
(defun evil-visual-post-command (&optional command)
"Run after each COMMAND in Visual state.
If COMMAND is a motion, refresh the selection;
otherwise exit Visual state."
(when (evil-visual-state-p)
(setq command (or command this-command))
(if (or quit-flag
(eq command #'keyboard-quit)
;; Is `mark-active' nil for an unexpanded region?
deactivate-mark
(and (not evil-visual-region-expanded)
(not (region-active-p))
(not (eq evil-visual-selection 'block))))
(progn
(evil-exit-visual-state)
(evil-adjust-cursor))
(if evil-visual-region-expanded
(evil-visual-contract-region)
(evil-visual-refresh))
(setq evil-visual-x-select-timer
(run-with-idle-timer evil-visual-x-select-timeout nil
#'evil-visual-update-x-selection
(current-buffer)))
(evil-visual-highlight))))
(put 'evil-visual-post-command 'permanent-local-hook t)
(defun evil-visual-update-x-selection (&optional buffer)
"Update the X selection with the current visual region."
(let ((buf (or buffer (current-buffer))))
(when (buffer-live-p buf)
(with-current-buffer buf
(when (and (evil-visual-state-p)
(display-selections-p)
(not (eq evil-visual-selection 'block)))
(evil-set-selection 'PRIMARY (buffer-substring-no-properties
evil-visual-beginning
evil-visual-end)))))))
(defun evil-visual-activate-hook (&optional _command)
"Enable Visual state if the region is activated."
(unless (evil-visual-state-p)
(evil-delay nil
;; the activation may only be momentary, so re-check
;; in `post-command-hook' before entering Visual state
'(unless (or (evil-visual-state-p)
(evil-insert-state-p)
(evil-emacs-state-p))
(when (and (region-active-p)
(not deactivate-mark))
(evil-visual-state)))
'post-command-hook nil t
"evil-activate-visual-state")))
(put 'evil-visual-activate-hook 'permanent-local-hook t)
(defun evil-visual-deactivate-hook (&optional command)
"Deactivate the region and restore Transient Mark mode."
(setq command (or command this-command))
(remove-hook 'deactivate-mark-hook
#'evil-visual-deactivate-hook t)
(remove-hook 'evil-normal-state-entry-hook
#'evil-visual-deactivate-hook t)
(cond
((and (evil-visual-state-p) command
(not (evil-get-command-property command :keep-visual)))
(setq evil-visual-region-expanded nil)
(evil-exit-visual-state))
((not (evil-visual-state-p))
(evil-active-region -1)
(evil-restore-transient-mark-mode))))
(put 'evil-visual-deactivate-hook 'permanent-local-hook t)
(evil-define-command evil-exit-visual-state (&optional later buffer)
"Exit from Visual state to the previous state.
If LATER is non-nil, exit after the current command."
:keep-visual t
:repeat abort
(with-current-buffer (or buffer (current-buffer))
(when (evil-visual-state-p)
(if later
(setq deactivate-mark t)
(when evil-visual-region-expanded
(evil-visual-contract-region))
(evil-change-to-previous-state)))))
(defun evil-visual-tag (&optional selection)
"Return a mode-line tag for SELECTION.
SELECTION is a kind of selection as defined by
`evil-define-visual-selection', such as `char', `line'
or `block'."
(setq selection (or selection evil-visual-selection))
(when selection
(symbol-value (intern (format "evil-visual-%s-tag" selection)))))
(defun evil-visual-message (&optional selection)
"Create an echo area message for SELECTION.
SELECTION is a kind of selection as defined by
`evil-define-visual-selection', such as `char', `line'
or `block'."
(let (message)
(setq selection (or selection evil-visual-selection))
(when selection
(setq message
(symbol-value (intern (format "evil-visual-%s-message"
selection))))
(cond
((functionp message)
(funcall message))
((stringp message)
(evil-echo "%s" message))))))
(defun evil-visual-select (beg end &optional type dir message)
"Create a Visual selection of type TYPE from BEG to END.
Point and mark are positioned so that the resulting selection
has the specified boundaries. If DIR is negative, point precedes mark,
otherwise it succedes it. To specify point and mark directly,
use `evil-visual-make-selection'."
(let* ((range (evil-contract beg end type))
(mark (evil-range-beginning range))
(point (evil-range-end range))
(dir (or dir 1)))
(when (< dir 0)
(evil-swap mark point))
(evil-visual-make-selection mark point type message)))
(defun evil-visual-make-selection (mark point &optional type message)
"Create a Visual selection with point at POINT and mark at MARK.
The boundaries of the selection are inferred from these
and the current TYPE. To specify the boundaries and infer
mark and point, use `evil-visual-select' instead."
(let* ((selection (evil-visual-selection-for-type type))
(func (evil-visual-selection-function selection))
(prev (and (evil-visual-state-p) evil-visual-selection))
(mark (evil-normalize-position mark))
(point (evil-normalize-position point))
(state evil-state))
(unless (evil-visual-state-p)
(evil-visual-state))
(setq evil-visual-selection selection)
(funcall func mark point type
;; signal a message when changing the selection
(when (or (not (evil-visual-state-p state))
(not (eq selection prev)))
message))))
(defun evil-visual-make-region (mark point &optional type message)
"Create an active region from MARK to POINT.
If TYPE is given, also set the Visual type.
If MESSAGE is given, display it in the echo area."
(interactive)
(let* ((point (evil-normalize-position
(or point (point))))
(mark (evil-normalize-position
(or mark
(when (or (evil-visual-state-p)
(region-active-p))
(mark t))
point))))
(unless (evil-visual-state-p)
(evil-visual-state))
(evil-active-region 1)
(setq evil-visual-region-expanded nil)
(evil-visual-refresh mark point type)
(cond
((null evil-echo-state))
((stringp message)
(evil-echo "%s" message))
(message
(cond
((stringp evil-visual-state-message)
(evil-echo "%s" evil-visual-state-message))
((functionp evil-visual-state-message)
(funcall evil-visual-state-message)))))))
(defun evil-visual-expand-region (&optional exclude-newline)
"Expand the region to the Visual selection.
If EXCLUDE-NEWLINE is non-nil and the selection ends with a newline,
exclude that newline from the region."
(when (and (evil-visual-state-p)
(not evil-visual-region-expanded))
(let ((mark evil-visual-beginning)
(point evil-visual-end))
(when (< evil-visual-direction 0)
(evil-swap mark point))
(setq evil-visual-region-expanded t)
(evil-visual-refresh mark point)
(when (and exclude-newline
(save-excursion
(goto-char evil-visual-end)
(and (bolp) (not (bobp)))))
(if (< evil-visual-direction 0)
(evil-move-mark (max point (1- (mark))))
(goto-char (max mark (1- (point)))))))))
(defun evil-visual-contract-region ()
"The inverse of `evil-visual-expand-region'.
Create a Visual selection that expands to the current region."
(evil-visual-refresh)
(setq evil-visual-region-expanded nil)
(evil-visual-refresh evil-visual-mark evil-visual-point))
(defun evil-visual-refresh (&optional mark point type &rest properties)
"Refresh point, mark and Visual variables.
Refreshes `evil-visual-beginning', `evil-visual-end',
`evil-visual-mark', `evil-visual-point', `evil-visual-selection',
`evil-visual-direction', `evil-visual-properties' and `evil-this-type'."
(let* ((point (or point (point)))
(mark (or mark (mark t) point))
(dir (evil-visual-direction))
(type (or type (evil-visual-type evil-visual-selection)
(evil-visual-type)))
range)
(evil-move-mark mark)
(goto-char point)
(setq evil-visual-beginning
(or evil-visual-beginning
(let ((marker (make-marker)))
(move-marker marker (min point mark))))
evil-visual-end
(or evil-visual-end
(let ((marker (make-marker)))
(set-marker-insertion-type marker t)
(move-marker marker (max point mark))))
evil-visual-mark
(or evil-visual-mark
(let ((marker (make-marker)))
(move-marker marker mark)))
evil-visual-point
(or evil-visual-point
(let ((marker (make-marker)))
(move-marker marker point))))
(setq evil-visual-properties
(evil-concat-plists evil-visual-properties properties))
(cond
(evil-visual-region-expanded
(setq type (or (evil-visual-type) type))
(move-marker evil-visual-beginning (min point mark))
(move-marker evil-visual-end (max point mark))
;; if the type is one-to-one, we can safely refresh
;; the unexpanded positions as well
(when (evil-type-property type :one-to-one)
(setq range (apply #'evil-contract point mark type
evil-visual-properties)
mark (evil-range-beginning range)
point (evil-range-end range))
(when (< dir 0)
(evil-swap mark point))
(move-marker evil-visual-mark mark)
(move-marker evil-visual-point point)))
(t
(setq range (apply #'evil-expand point mark type
evil-visual-properties)
type (evil-type range type))
(move-marker evil-visual-beginning (evil-range-beginning range))
(move-marker evil-visual-end (evil-range-end range))
(move-marker evil-visual-mark mark)
(move-marker evil-visual-point point)))
(setq evil-visual-direction dir
evil-this-type type)))
(defun evil-visual-highlight (&optional arg)
"Highlight Visual selection, depending on the Visual type.
With negative ARG, disable highlighting."
(cond
((and (numberp arg) (< arg 1))
(when evil-visual-overlay
(delete-overlay evil-visual-overlay)
(setq evil-visual-overlay nil))
(when evil-visual-block-overlays
(mapc #'delete-overlay evil-visual-block-overlays)
(setq evil-visual-block-overlays nil)))
((eq evil-visual-selection 'block)
(when evil-visual-overlay
(evil-visual-highlight -1))
(evil-visual-highlight-block
evil-visual-beginning
evil-visual-end))
(t
(when evil-visual-block-overlays
(evil-visual-highlight -1))
(if evil-visual-overlay
(move-overlay evil-visual-overlay
evil-visual-beginning evil-visual-end)
(setq evil-visual-overlay
(make-overlay evil-visual-beginning evil-visual-end)))
(overlay-put evil-visual-overlay 'face 'region)
(overlay-put evil-visual-overlay 'priority 99))))
(defun evil-visual-highlight-block (beg end &optional overlays)
"Highlight rectangular region from BEG to END.
Do this by putting an overlay on each line within the rectangle.
Each overlay extends across all the columns of the rectangle.
Reuse overlays where possible to prevent flicker."
(let* ((point (point))
(overlays (or overlays 'evil-visual-block-overlays))
(old (symbol-value overlays))
(eol-col (and (memq this-command '(next-line previous-line))
(numberp temporary-goal-column)
(1+ (min (round temporary-goal-column)
(1- most-positive-fixnum)))))
beg-col end-col new nlines overlay window-beg window-end)
(save-excursion
;; calculate the rectangular region represented by BEG and END,
;; but put BEG in the upper-left corner and END in the
;; lower-right if not already there
(setq beg-col (evil-column beg)
end-col (evil-column end))
(when (>= beg-col end-col)
(if (= beg-col end-col)
(setq end-col (1+ end-col))
(evil-sort beg-col end-col))
(setq beg (save-excursion
(goto-char beg)
(evil-move-to-column beg-col))
end (save-excursion
(goto-char end)
(evil-move-to-column end-col 1))))
;; update end column with eol-col (extension to eol).
(when (and eol-col (> eol-col end-col))
(setq end-col eol-col))
;; force a redisplay so we can do reliable window
;; BEG/END calculations
(sit-for 0)
(setq window-beg (max (window-start) beg)
window-end (min (window-end) (1+ end))
nlines (count-lines window-beg
(min window-end (point-max))))
;; iterate over those lines of the rectangle which are
;; visible in the currently selected window
(goto-char window-beg)
(dotimes (_ nlines)
(let (before after row-beg row-end)
;; beginning of row
(evil-move-to-column beg-col)
(when (< (current-column) beg-col)
;; prepend overlay with virtual spaces if unable to
;; move directly to the first column
(setq before
(propertize
(make-string
(- beg-col (current-column)) ?\s)
'face
(or (get-text-property (1- (point)) 'face)
'default))))
(setq row-beg (point))
;; end of row
(evil-move-to-column end-col)
(when (and (not (eolp))
(< (current-column) end-col))
;; append overlay with virtual spaces if unable to
;; move directly to the last column
(setq after
(propertize
(make-string
(if (= (point) row-beg)
(- end-col beg-col)
(- end-col (current-column)))
?\s) 'face 'region))
;; place cursor on one of the virtual spaces
(if (= point row-beg)
(put-text-property
0 (min (length after) 1)
'cursor t after)
(put-text-property
(max 0 (1- (length after))) (length after)
'cursor t after)))
(setq row-end (min (point) (line-end-position)))
;; trim old leading overlays
(while (and old
(setq overlay (car old))
(< (overlay-start overlay) row-beg)
(/= (overlay-end overlay) row-end))
(delete-overlay overlay)
(setq old (cdr old)))
;; reuse an overlay if possible, otherwise create one
(cond
((and old (setq overlay (car old))
(or (= (overlay-start overlay) row-beg)
(= (overlay-end overlay) row-end)))
(move-overlay overlay row-beg row-end)
(overlay-put overlay 'before-string before)
(overlay-put overlay 'after-string after)
(setq new (cons overlay new)
old (cdr old)))
(t
(setq overlay (make-overlay row-beg row-end))
(overlay-put overlay 'before-string before)
(overlay-put overlay 'after-string after)
(setq new (cons overlay new)))))
(forward-line 1))
;; display overlays
(dolist (overlay new)
(overlay-put overlay 'face 'region)
(overlay-put overlay 'priority 99))
;; trim old overlays
(dolist (overlay old)
(delete-overlay overlay))
(set overlays (nreverse new)))))
(defun evil-visual-range ()
"Return the Visual selection as a range.
This is a list (BEG END TYPE PROPERTIES...), where BEG is the
beginning of the selection, END is the end of the selection,
TYPE is the selection's type, and PROPERTIES is a property list
of miscellaneous selection attributes."
(apply #'evil-range
evil-visual-beginning evil-visual-end
(evil-visual-type)
:expanded t
evil-visual-properties))
(defun evil-visual-direction ()
"Return direction of Visual selection.
The direction is -1 if point precedes mark and 1 otherwise.
See also the variable `evil-visual-direction', which holds
the direction of the last selection."
(let* ((point (point))
(mark (or (mark t) point)))
(if (< point mark) -1 1)))
(defun evil-visual-type (&optional selection)
"Return the type of the Visual selection.
If SELECTION is specified, return the type of that instead."
(if (and (null selection) (evil-visual-state-p))
(or evil-this-type (evil-visual-type evil-visual-selection))
(setq selection (or selection evil-visual-selection))
(symbol-value (cdr-safe (assq selection evil-visual-alist)))))
(defun evil-visual-goto-end ()
"Go to the last line of the Visual selection.
This position may differ from `evil-visual-end' depending on
the selection type, and is contained in the selection."
(let ((range (evil-contract-range (evil-visual-range))))
(goto-char (evil-range-end range))))
(defun evil-visual-alist ()
"Return an association list from types to selection symbols."
(mapcar #'(lambda (e)
(cons (symbol-value (cdr-safe e)) (cdr-safe e)))
evil-visual-alist))
(defun evil-visual-selection-function (selection)
"Return a selection function for TYPE.
Default to `evil-visual-make-region'."
(or (cdr-safe (assq selection evil-visual-alist))
;; generic selection function
'evil-visual-make-region))
(defun evil-visual-selection-for-type (type)
"Return a Visual selection for TYPE."
(catch 'done
(dolist (selection evil-visual-alist)
(when (eq (symbol-value (cdr selection)) type)
(throw 'done (car selection))))))
(defun evil-visual-block-corner (&optional corner point mark)
"Block corner corresponding to POINT, with MARK in opposite corner.
Depending on POINT and MARK, the return value is `upper-left',
`upper-right', `lower-left' or `lower-right':
upper-left +---+ upper-right
| |
lower-left +---+ lower-right
One-column or one-row blocks are ambiguous. In such cases,
the horizontal or vertical component of CORNER is used.
CORNER defaults to `upper-left'."
(let* ((point (or point (point)))
(mark (or mark (mark t)))
(corner (symbol-name
(or corner
(and (overlayp evil-visual-overlay)
(overlay-get evil-visual-overlay
:corner))
'upper-left)))
(point-col (evil-column point))
(mark-col (evil-column mark))
horizontal vertical)
(cond
((= point-col mark-col)
(setq horizontal
(or (and (string-match "left\\|right" corner)
(match-string 0 corner))
"left")))
((< point-col mark-col)
(setq horizontal "left"))
((> point-col mark-col)
(setq horizontal "right")))
(cond
((= (line-number-at-pos point)
(line-number-at-pos mark))
(setq vertical
(or (and (string-match "upper\\|lower" corner)
(match-string 0 corner))
"upper")))
((< point mark)
(setq vertical "upper"))
((> point mark)
(setq vertical "lower")))
(intern (format "%s-%s" vertical horizontal))))
;;; Operator-Pending state
(evil-define-state operator
"Operator-Pending state."
:tag " <O> "
:cursor evil-half-cursor
:enable (evil-operator-shortcut-map operator motion normal))
(evil-define-keymap evil-operator-shortcut-map
"Keymap for Operator-Pending shortcuts like \"dd\" and \"gqq\"."
:local t
(setq evil-operator-shortcut-map (make-sparse-keymap))
(evil-initialize-local-keymaps))
;; the half-height "Operator-Pending cursor" cannot be specified
;; as a static `cursor-type' value, since its height depends on
;; the current font size
(defun evil-half-cursor ()
"Change cursor to a half-height box.
\(This is really just a thick horizontal bar.)"
(let ((height (/ (window-pixel-height) (* (window-height) 2))))
(setq cursor-type (cons 'hbar height))))
;;; Replace state
(evil-define-state replace
"Replace state."
:tag " <R> "
:cursor hbar
:message "-- REPLACE --"
:input-method t
(cond
((evil-replace-state-p)
(overwrite-mode 1)
(add-hook 'pre-command-hook #'evil-replace-pre-command nil t)
(unless (eq evil-want-fine-undo t)
(evil-start-undo-step)))
(t
(overwrite-mode -1)
(remove-hook 'pre-command-hook #'evil-replace-pre-command t)
(unless (eq evil-want-fine-undo t)
(evil-end-undo-step))
(evil-move-cursor-back)))
(setq evil-replace-alist nil))
(defun evil-replace-pre-command ()
"Remember the character under point."
(when (evil-replace-state-p)
(unless (assq (point) evil-replace-alist)
(add-to-list 'evil-replace-alist
(cons (point)
(unless (eolp)
(char-after)))))))
(put 'evil-replace-pre-command 'permanent-local-hook t)
(defun evil-replace-backspace ()
"Restore character under cursor."
(interactive)
(let (char)
(backward-char)
(when (assq (point) evil-replace-alist)
(setq char (cdr (assq (point) evil-replace-alist)))
(save-excursion
(delete-char 1)
(when char
(insert char))))))
;;; Motion state
(evil-define-state motion
"Motion state."
:tag " <M> "
:suppress-keymap t)
;;; Emacs state
(evil-define-state emacs
"Emacs state."
:tag " <E> "
:message "-- EMACS --"
:input-method t
:intercept-esc nil)
(provide 'evil-states)
;;; evil-states.el ends here

Binary file not shown.

View File

@ -0,0 +1,462 @@
;;; evil-types.el --- Type system -*- lexical-binding: t -*-
;; Author: Vegard Øye <vegard_oye at hotmail.com>
;; Maintainer: Vegard Øye <vegard_oye at hotmail.com>
;; Version: 1.14.0
;;
;; This file is NOT part of GNU Emacs.
;;; License:
;; This file is part of Evil.
;;
;; Evil is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; Evil is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with Evil. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; A type defines a transformation on a pair of buffer positions.
;; Types are used by Visual state (character/line/block selection)
;; and Operator-Pending state (character/line/block motions).
;;
;; The basic transformation is "expansion". For example, the `line'
;; type "expands" a pair of positions to whole lines by moving the
;; first position to the beginning of the line and the last position
;; to the end of the line. That expanded selection is what the rest
;; of Emacs sees and acts on.
;;
;; An optional transformation is "contraction", which is the opposite
;; of expansion. If the transformation is one-to-one, expansion
;; followed by contraction always returns the original range.
;; (The `line' type is not one-to-one, as it may expand multiple
;; positions to the same lines.)
;;
;; Another optional transformation is "normalization", which takes
;; two unexpanded positions and adjusts them before expansion.
;; This is useful for cleaning up "invalid" positions.
;;
;; Types are defined at the end of this file using the macro
;; `evil-define-type'.
(require 'evil-common)
(require 'evil-macros)
;;; Code:
;;; Type definitions
(evil-define-type exclusive
"Return the positions unchanged, with some exceptions.
If the end position is at the beginning of a line, then:
* If the beginning position is at or before the first non-blank
character on the line, return `line' (expanded).
* Otherwise, move the end position to the end of the previous
line and return `inclusive' (expanded)."
:normalize (lambda (beg end)
(cond
((progn
(goto-char end)
(and (/= beg end) (bolp)))
(setq end (max beg (1- end)))
(cond
((progn
(goto-char beg)
(looking-back "^[ \f\t\v]*" (line-beginning-position)))
(evil-expand beg end 'line))
(t
(unless evil-cross-lines
(setq end (max beg (1- end))))
(evil-expand beg end 'inclusive))))
(t
(evil-range beg end))))
:string (lambda (beg end)
(let ((width (- end beg)))
(format "%s character%s" width
(if (= width 1) "" "s")))))
(evil-define-type inclusive
"Include the character under point.
If the end position is at the beginning of a line or the end of a
line and `evil-want-visual-char-semi-exclusive', then:
* If in visual state return `exclusive' (expanded)."
:expand (lambda (beg end)
(if (and evil-want-visual-char-semi-exclusive
(evil-visual-state-p)
(< beg end)
(save-excursion
(goto-char end)
(or (bolp) (eolp))))
(evil-range beg end 'exclusive)
(evil-range beg (1+ end))))
:contract (lambda (beg end)
(evil-range beg (max beg (1- end))))
:normalize (lambda (beg end)
(goto-char end)
(when (eq (char-after) ?\n)
(setq end (max beg (1- end))))
(evil-range beg end))
:string (lambda (beg end)
(let ((width (- end beg)))
(format "%s character%s" width
(if (= width 1) "" "s")))))
(evil-define-type line
"Include whole lines."
:one-to-one nil
:expand (lambda (beg end)
(evil-range
(progn
(goto-char beg)
(min (line-beginning-position)
(progn
;; move to beginning of line as displayed
(evil-move-beginning-of-line)
(line-beginning-position))))
(progn
(goto-char end)
(max (line-beginning-position 2)
(progn
;; move to end of line as displayed
(evil-move-end-of-line)
(line-beginning-position 2))))))
:contract (lambda (beg end)
(evil-range beg (max beg (1- end))))
:string (lambda (beg end)
(let ((height (count-lines beg end)))
(format "%s line%s" height
(if (= height 1) "" "s")))))
(evil-define-type screen-line
"Include whole lines, being aware of `visual-line-mode'
when `evil-respect-visual-line-mode' is non-nil."
:one-to-one nil
:expand (lambda (beg end)
(if (or (not evil-respect-visual-line-mode)
(not visual-line-mode))
(evil-line-expand beg end)
(evil-range
(progn
(goto-char beg)
(save-excursion
(beginning-of-visual-line)))
(progn
(goto-char end)
(save-excursion
;; `beginning-of-visual-line' reverts to the beginning of the
;; last visual line if the end of the last line is the end of
;; the buffer. This would prevent selecting the last screen
;; line.
(if (= (line-beginning-position 2) (point-max))
(point-max)
(beginning-of-visual-line 2)))))))
:contract (lambda (beg end)
(evil-range beg (max beg (1- end))))
:string (lambda (beg end)
(let ((height (count-screen-lines beg end)))
(format "%s screen line%s" height
(if (= height 1) "" "s")))))
(evil-define-type block
"Like `inclusive', but for rectangles:
the last column is included."
:expand (lambda (beg end &rest properties)
(let ((beg-col (evil-column beg))
(end-col (evil-column end))
(corner (plist-get properties :corner)))
;; Since blocks are implemented as a pair of buffer
;; positions, expansion is restricted to what the buffer
;; allows. In the case of a one-column block, there are
;; two ways to expand it (either move the upper corner
;; beyond the lower corner, or the lower beyond the
;; upper), so try out both possibilities when
;; encountering the end of the line.
(cond
((= beg-col end-col)
(goto-char end)
(cond
((eolp)
(goto-char beg)
(if (eolp)
(evil-range beg end)
(evil-range (1+ beg) end)))
((memq corner '(lower-right upper-right right))
(evil-range (1+ beg) end))
(t
(evil-range beg (1+ end)))))
((< beg-col end-col)
(goto-char end)
(if (eolp)
(evil-range beg end)
(evil-range beg (1+ end))))
(t
(goto-char beg)
(if (eolp)
(evil-range beg end)
(evil-range (1+ beg) end))))))
:contract (lambda (beg end)
(let ((beg-col (evil-column beg))
(end-col (evil-column end)))
(if (> beg-col end-col)
(evil-range (1- beg) end)
(evil-range beg (max beg (1- end))))))
:string (lambda (beg end)
(let ((height (count-lines
beg
(progn
(goto-char end)
(if (and (bolp) (not (eobp)))
(1+ end)
end))))
(width (abs (- (evil-column beg)
(evil-column end)))))
(format "%s row%s and %s column%s"
height
(if (= height 1) "" "s")
width
(if (= width 1) "" "s"))))
:rotate (lambda (beg end &rest properties)
"Rotate block according to :corner property.
:corner can be one of `upper-left',``upper-right', `lower-left'
and `lower-right'."
(let ((left (evil-column beg))
(right (evil-column end))
(corner (or (plist-get properties :corner)
'upper-left)))
(evil-sort left right)
(goto-char beg)
(if (memq corner '(upper-right lower-left))
(move-to-column right)
(move-to-column left))
(setq beg (point))
(goto-char end)
(if (memq corner '(upper-right lower-left))
(move-to-column left)
(move-to-column right))
(setq end (point))
(setq properties (plist-put properties
:corner corner))
(apply #'evil-range beg end properties))))
(evil-define-type rectangle
"Like `exclusive', but for rectangles:
the last column is excluded."
:expand (lambda (beg end)
;; select at least one column
(if (= (evil-column beg) (evil-column end))
(evil-expand beg end 'block)
(evil-range beg end 'block))))
;;; Standard interactive codes
(evil-define-interactive-code "*"
"Signal error if the buffer is read-only."
(when buffer-read-only
(signal 'buffer-read-only nil)))
(evil-define-interactive-code "b" (prompt)
"Name of existing buffer."
(list (read-buffer prompt (current-buffer) t)))
(evil-define-interactive-code "c"
"Read character."
(list (read-char)))
(evil-define-interactive-code "p"
"Prefix argument converted to number."
(list (prefix-numeric-value current-prefix-arg)))
(evil-define-interactive-code "P"
"Prefix argument in raw form."
(list current-prefix-arg))
;;; Custom interactive codes
(evil-define-interactive-code "<c>"
"Count."
(list (when current-prefix-arg
(prefix-numeric-value
current-prefix-arg))))
(evil-define-interactive-code "<vc>"
"Count, but only in visual state.
This should be used by an operator taking a count. In normal
state the count should not be handled by the operator but by the
motion that defines the operator's range. In visual state the
range is specified by the visual region and the count is not used
at all. Thus in the case the operator may use the count
directly."
(list (when (and (evil-visual-state-p) current-prefix-arg)
(prefix-numeric-value
current-prefix-arg))))
(evil-define-interactive-code "<C>"
"Character read through `evil-read-key'."
(list
(if (evil-operator-state-p)
(evil-without-restriction (evil-read-key))
(evil-read-key))))
(evil-define-interactive-code "<r>"
"Untyped motion range (BEG END)."
(evil-operator-range))
(evil-define-interactive-code "<R>"
"Typed motion range (BEG END TYPE)."
(evil-operator-range t))
(evil-define-interactive-code "<v>"
"Typed motion range of visual range(BEG END TYPE).
If visual state is inactive then those values are nil."
(if (evil-visual-state-p)
(let ((range (evil-visual-range)))
(list (car range)
(cadr range)
(evil-type range)))
(list nil nil nil)))
(evil-define-interactive-code "<x>"
"Current register."
(list evil-this-register))
(evil-define-interactive-code "<y>"
"Current yank-handler."
(list (evil-yank-handler)))
(evil-define-interactive-code "<a>"
"Ex argument."
:ex-arg t
(list (when (evil-ex-p) evil-ex-argument)))
(evil-define-interactive-code "<N>" (prompt)
"Prefix argument, ex-arg or minibuffer input, converted to number"
(list (cond
(current-prefix-arg (prefix-numeric-value current-prefix-arg))
((and evil-ex-argument (evil-ex-p)) (string-to-number evil-ex-argument))
((evil-ex-p) nil)
(t (string-to-number (read-string prompt))))))
(evil-define-interactive-code "<f>"
"Ex file argument."
:ex-arg file
(list (when (evil-ex-p) (evil-ex-file-arg))))
(evil-define-interactive-code "<b>"
"Ex buffer argument."
:ex-arg buffer
(list (when (evil-ex-p) evil-ex-argument)))
(evil-define-interactive-code "<sh>"
"Ex shell command argument."
:ex-arg shell
(list (when (evil-ex-p) evil-ex-argument)))
(evil-define-interactive-code "<fsh>"
"Ex file or shell command argument."
:ex-arg file-or-shell
(list (when (evil-ex-p) evil-ex-argument)))
(evil-define-interactive-code "<sym>"
"Ex symbolic argument."
:ex-arg sym
(list (when (and (evil-ex-p) evil-ex-argument)
(intern evil-ex-argument))))
(evil-define-interactive-code "<addr>"
"Ex line number."
(list
(and (evil-ex-p)
(let ((expr (evil-ex-parse evil-ex-argument)))
(if (eq (car expr) 'evil-goto-line)
(save-excursion
(goto-char evil-ex-point)
(eval (cadr expr)))
(user-error "Invalid address"))))))
(evil-define-interactive-code "<!>"
"Ex bang argument."
:ex-bang t
(list (when (evil-ex-p) evil-ex-bang)))
(evil-define-interactive-code "</>"
"Ex delimited argument."
(when (evil-ex-p)
(evil-delimited-arguments evil-ex-argument)))
(evil-define-interactive-code "<g/>"
"Ex global argument."
(when (evil-ex-p)
(evil-ex-parse-global evil-ex-argument)))
(evil-define-interactive-code "<s/>"
"Ex substitution argument."
:ex-arg substitution
(when (evil-ex-p)
(evil-ex-get-substitute-info evil-ex-argument t)))
(evil-define-interactive-code "<xc/>"
"Ex register and count argument, both optional.
Can be used for commands such as :delete [REGISTER] [COUNT] where the
command can be called with either zero, one or two arguments. When the
argument is one, if it's numeric it's treated as a COUNT, otherwise -
REGISTER"
(when (evil-ex-p)
(evil-ex-get-optional-register-and-count evil-ex-argument)))
(defun evil-ex-get-optional-register-and-count (string)
"Parse STRING as an ex arg with both optional REGISTER and COUNT.
Returns a list (REGISTER COUNT)."
(let* ((split-args (split-string (or string "")))
(arg-count (length split-args))
(arg0 (car split-args))
(arg1 (cadr split-args))
(number-regex "^-?[1-9][0-9]*$")
(register nil)
(count nil))
(cond
;; :command REGISTER or :command COUNT
((= arg-count 1)
(if (string-match-p number-regex arg0)
(setq count arg0)
(setq register arg0)))
;; :command REGISTER COUNT
((eq arg-count 2)
(setq register arg0
count arg1))
;; more than 2 args aren't allowed
((> arg-count 2)
(user-error "Invalid use")))
;; if register is given, check it's valid
(when register
(unless (= (length register) 1)
(user-error "Invalid register"))
(setq register (string-to-char register)))
;; if count is given, check it's valid
(when count
(unless (string-match-p number-regex count)
(user-error "Invalid count"))
(setq count (string-to-number count))
(unless (> count 0)
(user-error "Invalid count")))
(list register count)))
(provide 'evil-types)
;;; evil-types.el ends here

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -0,0 +1,148 @@
;;; evil.el --- extensible vi layer
;; The following list of authors was kept up to date until the beginning of
;; 2017, when evil moved under new maintainers. For authors since then, please
;; consult the git logs.
;; Alessandro Piras <laynor at gmail.com>
;; Alexander Baier <alexander.baier at mailbox.org>
;; Antono Vasiljev <antono.vasiljev at gmail.com>
;; Bailey Ling <bling at live.ca>
;; Barry O'Reilly <gundaetiapo at gmail.com>
;; Christoph Lange <langec at web.de>
;; Daniel Reiter <danieltreiter at gmail.com>
;; Eivind Fonn <evfonn at gmail.com>
;; Emanuel Evans <emanuel.evans at gmail.com>
;; Eric Siegel <siegel.eric at gmail.com>
;; Eugene Yaremenko <w3techplayground at gmail.com>
;; Frank Fischer <frank-fischer at shadow-soft.de>
;; Frank Terbeck <ft at bewatermyfriend.org>
;; Gordon Gustafson <gordon3.14 at gmail.com>
;; Herbert Jones <jones.herbert at gmail.com>
;; Jonas Bernoulli <jonas at bernoul.li>
;; Jonathan Claggett <jclaggett at lonocloud.com>
;; José A. Romero L. <escherdragon at gmail.com>
;; Justin Burkett <justin at burkett.cc>
;; Lars Andersen <expez at expez.com>
;; Lintaro Ina <tarao.gnn at gmail.com>
;; Lukasz Wrzosek <wrzoski at mail.com>
;; Marian Schubert <maio at netsafe.cz>
;; Matthew Malcomson <>
;; Michael Markert <markert.michael at googlemail.com>
;; Mike Gerwitz <mikegerwitz at gnu.org>
;; Nikolai Weibull <now at bitwi.se>
;; phaebz <phaebz at gmail.com>
;; ralesi <scio62 at gmail.com>
;; Rodrigo Setti <rodrigosetti at gmail.com>
;; Sanel Zukan <sanelz at gmail.com>
;; Sarah Brofeldt <sarah at thinkmonster.(none)>
;; Simon Hafner <hafnersimon at gmail.com>
;; Stefan Wehr <mail at stefanwehr.de>
;; Sune Simonsen <sune.simonsen at jayway.com>
;; Thomas Hisch <thomas at opentech.at>
;; Tim Harper <timcharper at gmail.com>
;; Tom Willemse <tom at ryuslash.org>
;; Trevor Murphy <trevor.m.murphy at gmail.com>
;; Ulrich Müller <ulm at gentoo.org>
;; Vasilij Schneidermann <v.schneidermann at gmail.com>
;; Vegard Øye <vegard_oye at hotmail.com>
;; Winfred Lu <winfred.lu at gmail.com>
;; Wolfgang Jenkner <wjenkner at inode.at>
;; Xiao Hanyu <xiaohanyu1988 at gmail.com>
;; York Zhao <yzhao at telecor.com>
;; Maintainers: The emacs-evil team. <https://github.com/orgs/emacs-evil/people>
;; To get in touch, please use the bug tracker or the
;; mailing list (see below).
;; Created: 2011-03-01
;; Version: 1.14.0
;; Keywords: emulation, vim
;; URL: https://github.com/emacs-evil/evil
;; Repository: https://github.com/emacs-evil/evil.git
;; EmacsWiki: http://www.emacswiki.org/emacs/Evil
;; Bug tracker: https://github.com/emacs-evil/evil/issues
;; If you have bug reports, suggestions or patches, please
;; create an issue at the bug tracker (open for everyone).
;; Other discussions (tips, extensions) go to the mailing list.
;; Mailing list: <implementations-list at lists.ourproject.org>
;; Subscribe: http://tinyurl.com/implementations-list
;; Newsgroup: nntp://news.gmane.org/gmane.emacs.vim-emulation
;; Archives: http://dir.gmane.org/gmane.emacs.vim-emulation
;; You don't have to subscribe to post; we usually reply
;; within a few days and CC our replies back to you.
;;
;; This file is NOT part of GNU Emacs.
;;; License:
;; This file is part of Evil.
;;
;; Evil is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; Evil is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with Evil. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Evil is an extensible vi layer for Emacs. It emulates the main
;; features of Vim, and provides facilities for writing custom
;; extensions.
;;
;; Evil lives in a Git repository. To obtain Evil, do
;;
;; git clone git://github.com/emacs-evil/evil.git
;;
;; Move Evil to ~/.emacs.d/evil (or somewhere else in the `load-path').
;; Then add the following lines to ~/.emacs:
;;
;; (add-to-list 'load-path "~/.emacs.d/evil")
;; (require 'evil)
;; (evil-mode 1)
;;
;; Evil requires undo-redo (Emacs 28), undo-fu or undo-tree for redo
;; functionality. Otherwise, Evil uses regular Emacs undo.
;;
;; Evil requires `goto-last-change' and `goto-last-change-reverse'
;; function for the corresponding motions g; g, as well as the
;; last-change-register `.'. One package providing these functions is
;; goto-chg.el:
;;
;; http://www.emacswiki.org/emacs/GotoChg
;;
;; Without this package the corresponding motions will raise an error.
;;; Code:
(require 'evil-vars)
(require 'evil-common)
(require 'evil-core)
(require 'evil-states)
(require 'evil-repeat)
(require 'evil-macros)
(require 'evil-search)
(require 'evil-ex)
(require 'evil-digraphs)
(require 'evil-types)
(require 'evil-commands)
(require 'evil-jumps)
(require 'evil-maps)
(when evil-want-integration
(require 'evil-integration))
(when evil-want-keybinding
(require 'evil-keybindings))
(run-hooks 'evil-after-load-hook)
(provide 'evil)
;;; evil.el ends here

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,22 @@
;;; evil-mu4e-autoloads.el --- automatically extracted autoloads -*- lexical-binding: t -*-
;;
;;; Code:
(add-to-list 'load-path (directory-file-name
(or (file-name-directory #$) (car load-path))))
;;;### (autoloads nil "evil-mu4e" "evil-mu4e.el" (0 0 0 0))
;;; Generated autoloads from evil-mu4e.el
(register-definition-prefixes "evil-mu4e" '("evil-mu4e-"))
;;;***
;; Local Variables:
;; version-control: never
;; no-byte-compile: t
;; no-update-autoloads: t
;; coding: utf-8
;; End:
;;; evil-mu4e-autoloads.el ends here

View File

@ -0,0 +1,2 @@
;;; Generated package description from evil-mu4e.el -*- no-byte-compile: t -*-
(define-package "evil-mu4e" "20180613.1039" "evil-based key bindings for mu4e" '((emacs "24.4") (evil "1.2.10")) :commit "5b22c1e30246318f233264506272d770f63897ca" :authors '(("Joris Engbers" . "info@jorisengbers.nl")) :maintainer '("Joris Engbers" . "info@jorisengbers.nl") :url "https://github.com/JorisE/evil-mu4e")

View File

@ -0,0 +1,331 @@
;;; evil-mu4e.el --- evil-based key bindings for mu4e -*- lexical-binding: t -*-
;; Copyright (C) 2015-2018 Joris Engbers
;; Copyright (C) 2018 Pierre Neidhardt <ambrevar@gmail.com>
;; Author: Joris Engbers <info@jorisengbers.nl>
;; Homepage: https://github.com/JorisE/evil-mu4e
;; Version: 0.0.8
;; Package-Version: 20180613.1039
;; Package-Commit: 5b22c1e30246318f233264506272d770f63897ca
;; Package-Requires: ((emacs "24.4") (evil "1.2.10"))
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published
;; by the Free Software Foundation; either version 3, or (at your
;; option) any later version.
;;
;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; For a full copy of the GNU General Public License
;; see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; evil-mu4e keybindings for mu4e that make sense for Evil users. The following
;; keybindings are defined:
;;
;; General commands:
;; | Commmand | evil-mu4e | Alternative |
;; |--------------------------+-----------+-------------|
;; | Jump to maildir | J | |
;; | Update | u | |
;; | Compose message | cc | C |
;; | Kill update mail process | x | |
;; Commands for header-mode and view-mode:
;; | Command | evil-mu4e | Alternative |
;; |---------------------------------+-----------+-------------|
;; | Next message | C-j | |
;; | Previous message | C-k | |
;; | Mark the current thread as read | T | |
;; | Compose message | cc | C |
;; | Compose edit** | ce | E |
;; | Compose forward** | cf | F |
;; | Compose reply | cr | R |
;; | Change sorting*** | o | O |
;; | Rerun search | gr | |
;; | Toggle include related | zr | |
;; | Toggle threading | zt | |
;; | Toggle hide cited | za | |
;; | Skip duplicates | zd | |
;; | Show log | gl | |
;; | Select other view | gv | |
;; | Save attachement(s) | p | P |
;; | Save url | yu | |
;; | Go to url | gx | |
;; | Fetch url | gX | |
;;
;; - * denotes only in header-mode
;; - ** denotes Alternative only in header-mode
;; - *** denotes Alternative only in view-mode
;;
;;; Code:
(require 'evil)
(require 'mu4e)
(defcustom evil-mu4e-state 'normal
"State to use in mu4e buffers where keybindings are altered."
:group 'mu4e
:type 'symbol)
;;; By default all mu4e modes except for mu4e-compose-mode will start in
;;; evil-emacs-state. This section makes all modes start in `evil-mu4e-state'.
(defvar evil-mu4e-emacs-to-evil-mu4e-state-modes
'(mu4e-main-mode
mu4e-headers-mode
mu4e-view-mode
mu4e-org-mode)
"Modes that should switch from Emacs state to `evil-mu4e-state'.")
(defun evil-mu4e-set-state ()
"Associate all relevant modes with the evil-mu4e-state."
(dolist (mode evil-mu4e-emacs-to-evil-mu4e-state-modes)
(evil-set-initial-state mode evil-mu4e-state))
(evil-set-initial-state 'mu4e-compose-mode 'insert))
;;; Define bindings
;; TODO: Inhibit insert-state functions as per Evil Collection.
(defvar evil-mu4e-mode-map-bindings
`((,evil-mu4e-state mu4e-main-mode-map "J" mu4e~headers-jump-to-maildir)
(,evil-mu4e-state mu4e-main-mode-map "j" next-line)
(,evil-mu4e-state mu4e-main-mode-map "k" previous-line)
(,evil-mu4e-state mu4e-main-mode-map "u" mu4e-update-mail-and-index)
(,evil-mu4e-state mu4e-main-mode-map "gr" revert-buffer)
(,evil-mu4e-state mu4e-main-mode-map "b" mu4e-headers-search-bookmark)
(,evil-mu4e-state mu4e-main-mode-map "B" mu4e-headers-search-bookmark-edit)
(,evil-mu4e-state mu4e-main-mode-map "N" mu4e-news)
(,evil-mu4e-state mu4e-main-mode-map ";" mu4e-context-switch)
(,evil-mu4e-state mu4e-main-mode-map "H" mu4e-display-manual)
(,evil-mu4e-state mu4e-main-mode-map "C" mu4e-compose-new)
(,evil-mu4e-state mu4e-main-mode-map "cc" mu4e-compose-new)
(,evil-mu4e-state mu4e-main-mode-map "x" mu4e-kill-update-mail)
(,evil-mu4e-state mu4e-main-mode-map "A" mu4e-about)
(,evil-mu4e-state mu4e-main-mode-map "f" smtpmail-send-queued-mail)
(,evil-mu4e-state mu4e-main-mode-map "m" mu4e~main-toggle-mail-sending-mode)
(,evil-mu4e-state mu4e-main-mode-map "s" mu4e-headers-search)
(,evil-mu4e-state mu4e-main-mode-map "q" mu4e-quit)
(,evil-mu4e-state mu4e-headers-mode-map "q" mu4e~headers-quit-buffer)
(,evil-mu4e-state mu4e-headers-mode-map "J" mu4e~headers-jump-to-maildir)
(,evil-mu4e-state mu4e-headers-mode-map "C" mu4e-compose-new)
(,evil-mu4e-state mu4e-headers-mode-map "E" mu4e-compose-edit)
(,evil-mu4e-state mu4e-headers-mode-map "F" mu4e-compose-forward)
(,evil-mu4e-state mu4e-headers-mode-map "R" mu4e-compose-reply)
(,evil-mu4e-state mu4e-headers-mode-map "cc" mu4e-compose-new)
(,evil-mu4e-state mu4e-headers-mode-map "ce" mu4e-compose-edit)
(,evil-mu4e-state mu4e-headers-mode-map "cf" mu4e-compose-forward)
(,evil-mu4e-state mu4e-headers-mode-map "cr" mu4e-compose-reply)
(,evil-mu4e-state mu4e-headers-mode-map "o" mu4e-headers-change-sorting)
(,evil-mu4e-state mu4e-headers-mode-map "j" mu4e-headers-next)
(,evil-mu4e-state mu4e-headers-mode-map "k" mu4e-headers-prev)
(,evil-mu4e-state mu4e-headers-mode-map "gr" mu4e-headers-rerun-search)
(,evil-mu4e-state mu4e-headers-mode-map "b" mu4e-headers-search-bookmark)
(,evil-mu4e-state mu4e-headers-mode-map "B" mu4e-headers-search-bookmark-edit)
(,evil-mu4e-state mu4e-headers-mode-map ";" mu4e-context-switch)
(,evil-mu4e-state mu4e-headers-mode-map ,(kbd "RET") mu4e-headers-view-message)
(,evil-mu4e-state mu4e-headers-mode-map "/" mu4e-headers-search-narrow)
(,evil-mu4e-state mu4e-headers-mode-map "s" mu4e-headers-search)
(,evil-mu4e-state mu4e-headers-mode-map "S" mu4e-headers-search-edit)
(,evil-mu4e-state mu4e-headers-mode-map "x" mu4e-mark-execute-all)
(,evil-mu4e-state mu4e-headers-mode-map "a" mu4e-headers-action)
(,evil-mu4e-state mu4e-headers-mode-map "*" mu4e-headers-mark-for-something) ; TODO: Don't override evil-seach-word-forward?
(,evil-mu4e-state mu4e-headers-mode-map "&" mu4e-headers-mark-custom)
(,evil-mu4e-state mu4e-headers-mode-map "A" mu4e-headers-mark-for-action)
(,evil-mu4e-state mu4e-headers-mode-map "m" mu4e-headers-mark-for-move)
(,evil-mu4e-state mu4e-headers-mode-map "r" mu4e-headers-mark-for-refile)
(,evil-mu4e-state mu4e-headers-mode-map "D" mu4e-headers-mark-for-delete)
(,evil-mu4e-state mu4e-headers-mode-map "d" mu4e-headers-mark-for-trash)
(,evil-mu4e-state mu4e-headers-mode-map "=" mu4e-headers-mark-for-untrash)
(,evil-mu4e-state mu4e-headers-mode-map "u" mu4e-headers-mark-for-unmark)
(,evil-mu4e-state mu4e-headers-mode-map "U" mu4e-mark-unmark-all)
(,evil-mu4e-state mu4e-headers-mode-map "?" mu4e-headers-mark-for-unread)
(,evil-mu4e-state mu4e-headers-mode-map "!" mu4e-headers-mark-for-read)
(,evil-mu4e-state mu4e-headers-mode-map "%" mu4e-headers-mark-pattern)
(,evil-mu4e-state mu4e-headers-mode-map "+" mu4e-headers-mark-for-flag)
(,evil-mu4e-state mu4e-headers-mode-map "-" mu4e-headers-mark-for-unflag)
(,evil-mu4e-state mu4e-headers-mode-map "[" mu4e-headers-prev-unread)
(,evil-mu4e-state mu4e-headers-mode-map "]" mu4e-headers-next-unread)
(,evil-mu4e-state mu4e-headers-mode-map "gk" mu4e-headers-prev-unread)
(,evil-mu4e-state mu4e-headers-mode-map "gj" mu4e-headers-next-unread)
(,evil-mu4e-state mu4e-headers-mode-map "\C-j" mu4e-headers-next)
(,evil-mu4e-state mu4e-headers-mode-map "\C-k" mu4e-headers-prev)
(,evil-mu4e-state mu4e-headers-mode-map "zr" mu4e-headers-toggle-include-related)
(,evil-mu4e-state mu4e-headers-mode-map "zt" mu4e-headers-toggle-threading)
(,evil-mu4e-state mu4e-headers-mode-map "zd" mu4e-headers-toggle-skip-duplicates)
(,evil-mu4e-state mu4e-headers-mode-map "gl" mu4e-show-log)
(,evil-mu4e-state mu4e-headers-mode-map "gv" mu4e-select-other-view)
(,evil-mu4e-state mu4e-headers-mode-map "T" (lambda ()
(interactive)
(mu4e-headers-mark-thread nil '(read))))
;; (,evil-mu4e-state mu4e-compose-mode-map "gg" mu4e-compose-goto-top) ; TODO: Make this work.
(,evil-mu4e-state mu4e-view-mode-map ,(kbd "SPC") mu4e-view-scroll-up-or-next)
(,evil-mu4e-state mu4e-view-mode-map ,(kbd "<tab>") shr-next-link)
(,evil-mu4e-state mu4e-view-mode-map ,(kbd "<backtab>") shr-previous-link)
(,evil-mu4e-state mu4e-view-mode-map "q" mu4e~view-quit-buffer)
(,evil-mu4e-state mu4e-view-mode-map "gx" mu4e-view-go-to-url)
(,evil-mu4e-state mu4e-view-mode-map "gX" mu4e-view-fetch-url)
(,evil-mu4e-state mu4e-view-mode-map "C" mu4e-compose-new)
(,evil-mu4e-state mu4e-view-mode-map "H" mu4e-view-toggle-html)
;; (,evil-mu4e-state mu4e-view-mode-map "E" mu4e-compose-edit)
;; (,evil-mu4e-state mu4e-view-mode-map "F" mu4e-compose-forward)
(,evil-mu4e-state mu4e-view-mode-map "R" mu4e-compose-reply)
(,evil-mu4e-state mu4e-view-mode-map "cc" mu4e-compose-new)
(,evil-mu4e-state mu4e-view-mode-map "ce" mu4e-compose-edit)
(,evil-mu4e-state mu4e-view-mode-map "cf" mu4e-compose-forward)
(,evil-mu4e-state mu4e-view-mode-map "cr" mu4e-compose-reply)
(,evil-mu4e-state mu4e-view-mode-map "p" mu4e-view-save-attachment)
(,evil-mu4e-state mu4e-view-mode-map "P" mu4e-view-save-attachment-multi) ; Since mu4e 1.0, -multi is same as normal.
(,evil-mu4e-state mu4e-view-mode-map "O" mu4e-headers-change-sorting)
(,evil-mu4e-state mu4e-view-mode-map "o" mu4e-view-open-attachment)
(,evil-mu4e-state mu4e-view-mode-map "A" mu4e-view-attachment-action)
(,evil-mu4e-state mu4e-view-mode-map "a" mu4e-view-action)
(,evil-mu4e-state mu4e-view-mode-map "J" mu4e~headers-jump-to-maildir)
(,evil-mu4e-state mu4e-view-mode-map "[" mu4e-view-headers-prev-unread)
(,evil-mu4e-state mu4e-view-mode-map "]" mu4e-view-headers-next-unread)
(,evil-mu4e-state mu4e-view-mode-map "gk" mu4e-view-headers-prev-unread)
(,evil-mu4e-state mu4e-view-mode-map "gj" mu4e-view-headers-next-unread)
(,evil-mu4e-state mu4e-view-mode-map "\C-j" mu4e-view-headers-next)
(,evil-mu4e-state mu4e-view-mode-map "\C-k" mu4e-view-headers-prev)
(,evil-mu4e-state mu4e-view-mode-map "x" mu4e-view-marked-execute)
(,evil-mu4e-state mu4e-view-mode-map "&" mu4e-view-mark-custom)
(,evil-mu4e-state mu4e-view-mode-map "*" mu4e-view-mark-for-something) ; TODO: Don't override "*".
(,evil-mu4e-state mu4e-view-mode-map "m" mu4e-view-mark-for-move)
(,evil-mu4e-state mu4e-view-mode-map "r" mu4e-view-mark-for-refile)
(,evil-mu4e-state mu4e-view-mode-map "D" mu4e-view-mark-for-delete)
(,evil-mu4e-state mu4e-view-mode-map "d" mu4e-view-mark-for-trash)
(,evil-mu4e-state mu4e-view-mode-map "=" mu4e-view-mark-for-untrash)
(,evil-mu4e-state mu4e-view-mode-map "u" mu4e-view-unmark)
(,evil-mu4e-state mu4e-view-mode-map "U" mu4e-view-unmark-all)
(,evil-mu4e-state mu4e-view-mode-map "?" mu4e-view-mark-for-unread)
(,evil-mu4e-state mu4e-view-mode-map "!" mu4e-view-mark-for-read)
(,evil-mu4e-state mu4e-view-mode-map "%" mu4e-view-mark-pattern)
(,evil-mu4e-state mu4e-view-mode-map "+" mu4e-view-mark-for-flag)
(,evil-mu4e-state mu4e-view-mode-map "-" mu4e-view-mark-for-unflag)
(,evil-mu4e-state mu4e-view-mode-map "\C-u" evil-scroll-up)
(,evil-mu4e-state mu4e-view-mode-map "zr" mu4e-headers-toggle-include-related)
(,evil-mu4e-state mu4e-view-mode-map "zt" mu4e-headers-toggle-threading)
(,evil-mu4e-state mu4e-view-mode-map "za" mu4e-view-toggle-hide-cited)
(,evil-mu4e-state mu4e-view-mode-map "gl" mu4e-show-log)
(,evil-mu4e-state mu4e-view-mode-map "s" mu4e-view-search-edit)
(,evil-mu4e-state mu4e-view-mode-map "|" mu4e-view-pipe)
(,evil-mu4e-state mu4e-view-mode-map "." mu4e-view-raw-message)
(,evil-mu4e-state mu4e-view-mode-map ,(kbd "C--") mu4e-headers-split-view-shrink)
(,evil-mu4e-state mu4e-view-mode-map ,(kbd "C-+") mu4e-headers-split-view-grow)
(,evil-mu4e-state mu4e-view-mode-map "T" (lambda ()
(interactive)
(mu4e-headers-mark-thread nil '(read)))))
;; TODO: Add mu4e-headers-search-bookmark?
"All evil-mu4e bindings.")
(defun evil-mu4e-set-bindings ()
"Set the bindings."
;; WARNING: With lexical binding, lambdas from `mapc' and `dolist' become
;; closures in which we must use `evil-define-key*' instead of
;; `evil-define-key'.
(dolist (binding evil-mu4e-mode-map-bindings)
(evil-define-key*
(nth 0 binding) (nth 1 binding) (nth 2 binding) (nth 3 binding)))
(evil-define-key 'operator mu4e-view-mode-map
"u" '(menu-item
""
nil
:filter (lambda (&optional _)
(when (memq evil-this-operator
'(evil-yank evil-cp-yank evil-sp-yank lispyville-yank))
(setq evil-inhibit-operator t)
#'mu4e-view-save-url)))))
;;; Update mu4e-main-view
;;; To avoid confusion the main-view is updated to show the keys that are in use
;;; for evil-mu4e.
(defvar evil-mu4e-begin-region-basic "\n Basics"
"The place where to start overriding Basic section.")
(defvar evil-mu4e-end-region-basic "a new message\n"
"The place where to end overriding Basic section.")
(defvar evil-mu4e-new-region-basic
(concat (mu4e~main-action-str "\t* [J]ump to some maildir\n" 'mu4e-jump-to-maildir)
(mu4e~main-action-str "\t* enter a [s]earch query\n" 'mu4e-search)
(mu4e~main-action-str "\t* [C]ompose a new message\n" 'mu4e-compose-new))
"Define the evil-mu4e Basic region.")
(defvar evil-mu4e-begin-region-misc "\n Misc"
"The place where to start overriding Misc section.")
(defvar evil-mu4e-end-region-misc "q]uit"
"The place where to end overriding Misc section.")
(defvar evil-mu4e-new-region-misc
(concat
(mu4e~main-action-str "\t* [;]Switch focus\n" 'mu4e-context-switch)
(mu4e~main-action-str "\t* [u]pdate email & database (Alternatively: gr)\n"
'mu4e-update-mail-and-index)
;; show the queue functions if `smtpmail-queue-dir' is defined
(if (file-directory-p smtpmail-queue-dir)
(mu4e~main-view-queue)
"")
"\n"
(mu4e~main-action-str "\t* [N]ews\n" 'mu4e-news)
(mu4e~main-action-str "\t* [A]bout mu4e\n" 'mu4e-about)
(mu4e~main-action-str "\t* [H]elp\n" 'mu4e-display-manual)
(mu4e~main-action-str "\t* [q]uit\n" 'mu4e-quit))
"Define the evil-mu4e Misc region.")
(defun evil-mu4e-replace-region (new-region start end)
"Replace region between START and END with NEW-REGION.
START end END end are regular expressions."
;; move to start of region
(goto-char (point-min))
(re-search-forward start)
;; insert new headings
(insert "\n\n")
(insert new-region)
;; Delete text until end of region.
(let ((start-point (point))
(end-point (re-search-forward end)))
(delete-region start-point end-point)))
(defun evil-mu4e-update-main-view ()
"Update 'Basic' and 'Misc' regions to reflect the new
keybindings."
(evil-mu4e-replace-region evil-mu4e-new-region-basic
evil-mu4e-begin-region-basic evil-mu4e-end-region-basic)
(evil-mu4e-replace-region evil-mu4e-new-region-misc
evil-mu4e-begin-region-misc evil-mu4e-end-region-misc))
;;; Initialize evil-mu4e
(defun evil-mu4e-init ()
"Initialize evil-mu4e if necessary.
If mu4e-main-mode is in evil-state-motion-modes, initialization
is already done earlier."
(evil-mu4e-set-state)
(evil-mu4e-set-bindings)
(add-hook 'mu4e-main-mode-hook 'evil-mu4e-update-main-view))
;; Evil-mu4e is only needed if mu4e is loaded.
(with-eval-after-load 'mu4e
(evil-mu4e-init))
(provide 'evil-mu4e)
;;; evil-mu4e.el ends here

Binary file not shown.

View File

@ -0,0 +1,55 @@
;;; goto-chg-autoloads.el --- automatically extracted autoloads -*- lexical-binding: t -*-
;;
;;; Code:
(add-to-list 'load-path (directory-file-name
(or (file-name-directory #$) (car load-path))))
;;;### (autoloads nil "goto-chg" "goto-chg.el" (0 0 0 0))
;;; Generated autoloads from goto-chg.el
(autoload 'goto-last-change "goto-chg" "\
Go to the point where the last edit was made in the current buffer.
Repeat the command to go to the second last edit, etc.
To go back to more recent edit, the reverse of this command, use \\[goto-last-change-reverse]
or precede this command with \\[universal-argument] - (minus).
It does not go to the same point twice even if there has been many edits
there. I call the minimal distance between distinguishable edits \"span\".
Set variable `glc-default-span' to control how close is \"the same point\".
Default span is 8.
The span can be changed temporarily with \\[universal-argument] right before \\[goto-last-change]:
\\[universal-argument] <NUMBER> set current span to that number,
\\[universal-argument] (no number) multiplies span by 4, starting with default.
The so set span remains until it is changed again with \\[universal-argument], or the consecutive
repetition of this command is ended by any other command.
When span is zero (i.e. \\[universal-argument] 0) subsequent \\[goto-last-change] visits each and
every point of edit and a message shows what change was made there.
In this case it may go to the same point twice.
This command uses undo information. If undo is disabled, so is this command.
At times, when undo information becomes too large, the oldest information is
discarded. See variable `undo-limit'.
\(fn ARG)" t nil)
(autoload 'goto-last-change-reverse "goto-chg" "\
Go back to more recent changes after \\[goto-last-change] have been used.
See `goto-last-change' for use of prefix argument.
\(fn ARG)" t nil)
(register-definition-prefixes "goto-chg" '("glc-"))
;;;***
;; Local Variables:
;; version-control: never
;; no-byte-compile: t
;; no-update-autoloads: t
;; coding: utf-8
;; End:
;;; goto-chg-autoloads.el ends here

View File

@ -0,0 +1,2 @@
;;; Generated package description from goto-chg.el -*- no-byte-compile: t -*-
(define-package "goto-chg" "20201101.1029" "goto last change" 'nil :commit "2af612153bc9f5bed135d25abe62f46ddaa9027f" :authors '(("David Andersson <l.david.andersson(at)sverige.nu>")) :maintainer '("Vasilij Schneidermann" . "mail@vasilij.de") :keywords '("convenience" "matching") :url "https://github.com/emacs-evil/goto-chg")

View File

@ -0,0 +1,385 @@
;;; goto-chg.el --- goto last change
;;--------------------------------------------------------------------
;;
;; Copyright (C) 2002-2008,2013 David Andersson
;;
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2 of
;; the License, or (at your option) any later version.
;;
;; This program is distributed in the hope that it will be
;; useful, but WITHOUT ANY WARRANTY; without even the implied
;; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
;; PURPOSE. See the GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public
;; License along with this program; if not, write to the Free
;; Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301 USA
;;
;;-------------------------------------------------------------------
;;
;; Author: David Andersson <l.david.andersson(at)sverige.nu>
;; Maintainer: Vasilij Schneidermann <mail@vasilij.de>
;; Created: 16 May 2002
;; Version: 1.7.3
;; Package-Version: 20201101.1029
;; Package-Commit: 2af612153bc9f5bed135d25abe62f46ddaa9027f
;; Keywords: convenience, matching
;; URL: https://github.com/emacs-evil/goto-chg
;;
;;; Commentary:
;;
;; Goto Last Change
;;
;; Goto the point of the most recent edit in the buffer.
;; When repeated, goto the second most recent edit, etc.
;; Negative argument, C-u -, for reverse direction.
;; Works by looking into buffer-undo-list to find points of edit.
;;
;; You would probably like to bind this command to a key.
;; For example in your ~/.emacs:
;;
;; (require 'goto-chg)
;;
;; (global-set-key [(control ?.)] 'goto-last-change)
;; (global-set-key [(control ?,)] 'goto-last-change-reverse)
;;
;; Works with emacs-19.29, 19.31, 20.3, 20.7, 21.1, 21.4, 22.1 and 23.1
;; Works with XEmacs-20.4 and 21.4 (but see todo about `last-command' below)
;;
;;--------------------------------------------------------------------
;; History
;;
;; Ver 1.7.3 2019-01-07 Vasilij Schneidermann
;; Fix errors when used with persistent undo
;; Ver 1.7.2 2018-01-05 Vasilij Schneidermann
;; Fix byte-compiler warnings again
;; Ver 1.7.1 2017-12-31 Vasilij Schneidermann
;; Fix byte-compiler warnings
;; Ver 1.7 2017-09-17 Vasilij Schneidermann
;; Make it work with undo-tree-mode (see
;; <https://github.com/martinp26/goto-chg>)
;; Ver 1.6 2013-12-12 David Andersson
;; Add keywords; Cleanup comments
;; Ver 1.5 2013-12-11 David Andersson
;; Autoload and document `goto-last-change-reverse'
;; Ver 1.4 2008-09-20 David Andersson
;; Improved property change description; Update comments.
;; Ver 1.3 2007-03-14 David Andersson
;; Added `goto-last-change-reverse'
;; Ver 1.2 2003-04-06 David Andersson
;; Don't let repeating error depthen glc-probe-depth.
;; Ver 1.1 2003-04-06 David Andersson
;; Zero arg describe changes. Negative arg go back.
;; Autoload. Remove message using nil in stead of an empty string.
;; Ver 1.0 2002-05-18 David Andersson
;; Initial version
;;
;;--------------------------------------------------------------------
;;
;;todo: Rename "goto-chg.el" -> "gotochange.el" or "goto-chgs" ?
;;todo: Rename function goto-last-change -> goto-last-edit ?
;;todo: Rename adjective "-last-" -> "-latest-" or "-most-recent-" ?
;;todo: There are some, maybe useful, funcs for region undo
;; in simple.el in emacs 20. Take a look.
;;todo: Add functionality to visit changed point in text order, not only in
;; chronological order. (Naa, highlight-changes-mode does that).
;;todo: Inverse indication that a change has been saved or not
;;todo: Highlight the range of text involved in the last change?
;;todo: See session-jump-to-last-change in session.el?
;;todo: Unhide invisible text (e.g. outline mode) like isearch do.
;;todo: XEmacs sets last-command to `t' after an error, so you cannot reverse
;; after "No furter change info". Should we bother?
;;todo: Try distinguish "No further change info" (end of truncated undo list)
;; and "No further changes" (end of a complete undo list).
;;
;;--------------------------------------------------------------------
;;; Code:
(require 'undo-tree nil t)
(defvar glc-default-span 8 "*goto-last-change don't visit the same point twice. glc-default-span tells how far around a visited point not to visit again.")
(defvar glc-current-span 8 "Internal for goto-last-change.\nA copy of glc-default-span or the ARG passed to goto-last-change.")
(defvar glc-probe-depth 0 "Internal for goto-last-change.\nIt is non-zero between successive goto-last-change.")
(defvar glc-direction 1 "Direction goto-last-change moves towards.")
;;todo: Find begin and end of line, then use it somewhere
(defun glc-fixup-edit (e)
"Convert an Emacs 27.1-style combined change to a regular edit."
(when (and (consp e)
(eq (car e) 'apply)
(not (functionp (cadr e)))
(eq (nth 4 e) 'undo--wrap-and-run-primitive-undo))
(let ((args (last e)))
(when (and (consp args) (= (length args) 1)
(consp (car args)) (= (length (car args)) 1)
(consp (caar args)) (numberp (car (caar args))) (numberp (cdr (caar args))))
(setq e (caar args)))))
e)
(defun glc-center-ellipsis (str maxlen &optional ellipsis)
"Truncate STRING in the middle to length MAXLEN.
If STRING is max MAXLEN just return the string.
Optional third argument is the replacement, which defaults to \"...\"."
(if (<= (length str) maxlen)
str
;; else
(let* ((lipsis (or ellipsis "..."))
(i (/ (- maxlen (length lipsis)) 2)))
(concat (substring str 0 i)
lipsis
(substring str (- i))))))
(defun glc-adjust-pos2 (pos p1 p2 adj)
;; Helper function to glc-adjust-pos
;; p1, p2: interval where an edit occured
;; adj: amount of text added (positive) or removed (negativ) by the edit
;; Return pos if well before p1, or pos+adj if well after p2, or nil if too close
(cond ((<= pos (- p1 glc-current-span))
pos)
((> pos (+ p2 glc-current-span))
(+ pos adj))
((zerop glc-current-span)
p1)
(t
nil)))
(defun glc-adjust-pos (pos e)
"Given POS, a buffer position before the edit E, compute and return
the \"same\" buffer position after E happened.
Exception: return nil if POS is closer than `glc-current-span' to the edit E.
\nInsertion edits before POS returns a larger value.
Deletion edits before POS returns a smaller value.
\nThe edit E is an entry from the `buffer-undo-list'. See for details."
(setq e (glc-fixup-edit e))
(cond ((atom e) ; nil==cmd boundary, or, num==changed pos
pos)
((numberp (car e)) ; (beg . end)==insertion
(glc-adjust-pos2 pos (car e) (car e) (- (cdr e) (car e))))
((stringp (car e)) ; (string . pos)==deletion
(glc-adjust-pos2 pos (abs (cdr e)) (+ (abs (cdr e)) (length (car e))) (- (length (car e)))))
((null (car e)) ; (nil prop val beg . end)==prop change
(glc-adjust-pos2 pos (nth 3 e) (nthcdr 4 e) 0))
(t ; (marker . dist)==marker moved
pos)))
;; If recursive in stead of iterative (while), it tends to fill the call stack.
;; (Isn't it tail optimized?)
(defun glc-adjust-list (r)
"R is list of edit entries in chronological order.
Pick the point of the first edit entry and update that point with
the second, third, etc, edit entries. Return the final updated point,
or nil if the point was closer than `glc-current-span' to some edit in R.
\nR is basically a reversed slice from the buffer-undo-list."
(if r
;; Get pos
(let ((pos (glc-get-pos (car r))))
(setq r (cdr r))
;; Walk back in reverse list
(while (and r pos)
(setq pos (glc-adjust-pos pos (car r))
r (cdr r)))
pos)
;; else
nil))
(defun glc-get-pos (e)
"If E represents an edit, return a position value in E, the position
where the edit took place. Return nil if E represents no real change.
\nE is an entry in the buffer-undo-list."
(setq e (glc-fixup-edit e))
(cond ((numberp e) e) ; num==changed position
((atom e) nil) ; nil==command boundary
((numberp (car e)) (cdr e)) ; (beg . end)==insertion
((stringp (car e)) (abs (cdr e))) ; (string . pos)==deletion
((null (car e)) (nthcdr 4 e)) ; (nil ...)==text property change
((atom (car e)) nil) ; (t ...)==file modification time
(t nil))) ; (marker ...)==marker moved
(defun glc-get-descript (e &optional n)
"If E represents an edit, return a short string describing E.
Return nil if E represents no real change.
\nE is an entry in the buffer-undo-list."
(setq e (glc-fixup-edit e))
(let ((nn (or (format "T-%d: " n) "")))
(cond ((numberp e) "New position") ; num==changed position
((atom e) nil) ; nil==command boundary
((numberp (car e)) ; (beg . end)==insertion
(if (and n (< n 2))
(format "%sInserted %d chars \"%s\"" nn (- (cdr e) (car e))
(glc-center-ellipsis (buffer-substring (car e) (cdr e)) 60))
;; else
;; An older insert. The inserted text cannot easily be computed.
;; Just show the char count.
(format "%sInserted %d chars" nn (- (cdr e) (car e)))))
((stringp (car e)) ; (string . pos)==deletion
(format "%sDeleted \"%s\"" nn (glc-center-ellipsis (car e) 60)))
((null (car e)) ; (nil ...)==text property change
(format "%sProperty change" nn))
((atom (car e)) nil) ; (t ...)==file modification time
(t nil)))) ; (marker ...)==marker moved
(defun glc-is-positionable (e)
"Return non-nil if E is an insertion, deletion or text property change.
\nE is an entry in the buffer-undo-list."
(and (not (numberp e)) (glc-get-pos e)))
(defun glc-is-filetime (e)
"Return t if E indicates a buffer became \"modified\",
that is, it was previously saved or unchanged. Nil otherwise."
(and (listp e) (eq (car e) t)))
(declare-function undo-tree-current "ext:undo-tree")
(declare-function undo-tree-node-previous "ext:undo-tree")
(declare-function undo-tree-node-undo "ext:undo-tree")
(declare-function undo-list-transfer-to-tree "ext:undo-tree")
(defvar buffer-undo-tree)
;;;###autoload
(defun goto-last-change (arg)
"Go to the point where the last edit was made in the current buffer.
Repeat the command to go to the second last edit, etc.
\nTo go back to more recent edit, the reverse of this command, use \\[goto-last-change-reverse]
or precede this command with \\[universal-argument] - (minus).
\nIt does not go to the same point twice even if there has been many edits
there. I call the minimal distance between distinguishable edits \"span\".
Set variable `glc-default-span' to control how close is \"the same point\".
Default span is 8.
The span can be changed temporarily with \\[universal-argument] right before \\[goto-last-change]:
\\[universal-argument] <NUMBER> set current span to that number,
\\[universal-argument] (no number) multiplies span by 4, starting with default.
The so set span remains until it is changed again with \\[universal-argument], or the consecutive
repetition of this command is ended by any other command.
\nWhen span is zero (i.e. \\[universal-argument] 0) subsequent \\[goto-last-change] visits each and
every point of edit and a message shows what change was made there.
In this case it may go to the same point twice.
\nThis command uses undo information. If undo is disabled, so is this command.
At times, when undo information becomes too large, the oldest information is
discarded. See variable `undo-limit'."
(interactive "P")
(cond ((not (eq this-command last-command))
;; Start a glc sequence
;; Don't go to current point if last command was an obvious edit
;; (yank or self-insert, but not kill-region). Makes it easier to
;; jump back and forth when copying seleced lines.
(setq glc-probe-depth (if (memq last-command '(yank self-insert-command)) 1 0)
glc-direction 1
glc-current-span glc-default-span)
(if (< (prefix-numeric-value arg) 0)
(error "Negative arg: Cannot reverse as the first operation"))))
(cond ((and (null buffer-undo-list)
(or (not (boundp 'buffer-undo-tree))
(null buffer-undo-tree)))
(error "Buffer has not been changed"))
((eq buffer-undo-list t)
(error "No change info (undo is disabled)")))
(cond ((numberp arg) ; Numeric arg sets span
(setq glc-current-span (abs arg)))
((consp arg) ; C-u's multiply previous span by 4
(setq glc-current-span (* (abs (car arg)) glc-default-span))
(message "Current span is %d chars" glc-current-span))) ;todo: keep message with "waiting" and "is saved"
(cond ((< (prefix-numeric-value arg) 0)
(setq glc-direction -1))
(t
(setq glc-direction 1)))
(let (rev ; Reversed (and filtered) undo list
pos ; The pos we look for, nil until found
(n 0) ; Steps in undo list (length of 'rev')
(l buffer-undo-list)
(passed-save-entry (not (buffer-modified-p)))
(new-probe-depth glc-probe-depth)
(undo-tree-p (bound-and-true-p undo-tree-mode))
glc-seen-canary)
;; Walk back and forth in the buffer-undo-list, each time one step deeper,
;; until we can walk back the whole list with a 'pos' that is not coming
;; too close to another edit.
(while (null pos)
(setq new-probe-depth (+ new-probe-depth glc-direction))
(if (< glc-direction 0)
(setq rev ()
n 0
l buffer-undo-list
passed-save-entry (not (buffer-modified-p))))
(if (< new-probe-depth 1)
(error "No later change info"))
(if (> n 150)
(message "working..."))
;; Walk forward in buffer-undo-list, glc-probe-depth steps.
;; Build reverse list along the way
(if (not undo-tree-p)
(while (< n new-probe-depth)
(cond ((null l)
;(setq this-command t) ; Disrupt repeat sequence
(error "No further change info"))
((glc-is-positionable (car l))
(setq n (1+ n)
rev (cons (car l) rev)))
((or passed-save-entry (glc-is-filetime (car l)))
(setq passed-save-entry t)))
(setq l (cdr l)))
(undo-list-transfer-to-tree)
(when (not glc-seen-canary)
(while (and (not (null l)) (not glc-seen-canary) (< n new-probe-depth))
(cond ((eq 'undo-tree-canary (car l)) ; used by buffer-undo-tree
(message "Canary found...")
(setq l (undo-tree-current buffer-undo-tree)
glc-seen-canary t))
((glc-is-positionable (car l))
(setq n (1+ n)
rev (cons (car l) rev)))
((or passed-save-entry (glc-is-filetime (car l)))
(setq passed-save-entry t)))
(when (not glc-seen-canary)
(setq l (cdr l)))))
(when glc-seen-canary
(while (and (< n new-probe-depth) (eval '(undo-tree-node-p l)))
(cond ((null l)
;(setq this-command t) ; Disrupt repeat sequence
(error "No further change info"))
((glc-is-positionable (car (undo-tree-node-undo l)))
(setq n (1+ n)
rev (cons (car (undo-tree-node-undo l)) rev)))
((or passed-save-entry (glc-is-filetime (car (undo-tree-node-undo l))))
(setq passed-save-entry t)))
(setq l (undo-tree-node-previous l))))
(when (null l)
(error "No further change info")))
;; Walk back in reverse list, from older to newer edits.
;; Adjusting pos along the way.
(setq pos (glc-adjust-list rev)))
;; Found a place not previously visited, in 'pos'.
;; (An error have been issued if nothing (more) found.)
(if (> n 150)
(message nil)) ; remove message "working..."
(if (and (= glc-current-span 0) (glc-get-descript (car rev) n))
(message "%s" (glc-get-descript (car rev) n))
;; else
(if passed-save-entry
(message "(This change is saved)")))
(setq glc-probe-depth new-probe-depth)
(goto-char pos)))
;;;###autoload
(defun goto-last-change-reverse (arg)
"Go back to more recent changes after \\[goto-last-change] have been used.
See `goto-last-change' for use of prefix argument."
(interactive "P")
;; Negate arg, all kinds
(cond ((eq arg nil) (setq arg '-))
((eq arg '-) (setq arg nil))
((listp arg) (setq arg (list (- (car arg)))))
(t (setq arg (- arg))))
;; Make 'goto-last-change-reverse' look like 'goto-last-change'
(cond ((eq last-command this-command)
(setq last-command 'goto-last-change)))
(setq this-command 'goto-last-change)
;; Call 'goto-last-change' to do the job
(goto-last-change arg))
(provide 'goto-chg)
;;; goto-chg.el ends here

Binary file not shown.

View File

@ -151,7 +151,7 @@
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(package-selected-packages
'(exwm org-inline-pdf mu4e evil-magit magit general workgroups2 ERC dashboard doom-themes counsel ivy-rich which-key rainbow-delimiters doom-modeline use-package shrink-path ivy command-log-mode all-the-icons))
'(evil-mu4e exwm org-inline-pdf mu4e evil-magit magit general workgroups2 ERC dashboard doom-themes counsel ivy-rich which-key rainbow-delimiters doom-modeline use-package shrink-path ivy command-log-mode all-the-icons))
'(send-mail-function 'smtpmail-send-it)
'(smtpmail-smtp-server "disroot.org")
'(smtpmail-smtp-service 25))
@ -171,4 +171,8 @@
(require 'mu4e)
(setq user-full-name "Syed Ahmed")
(setq user-mail-address "9ahmed@disroot.org")
(setq mu4e-get-mail-command "mbsync -a")