[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/evil 4317b2eead 1/2: Global print using message
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/evil 4317b2eead 1/2: Global print using message |
Date: |
Fri, 2 Jun 2023 10:00:53 -0400 (EDT) |
branch: elpa/evil
commit 4317b2eead031d2d0dbcde1d143617c1e3f4a00d
Author: Tom Dalziel <tom_dl@hotmail.com>
Commit: Tom Dalziel <33435574+tomdl89@users.noreply.github.com>
Global print using message
---
evil-commands.el | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
evil-ex.el | 2 +-
evil-maps.el | 3 +++
evil-vars.el | 12 ++++++++-
4 files changed, 83 insertions(+), 8 deletions(-)
diff --git a/evil-commands.el b/evil-commands.el
index 2bcf08593a..3c6b2b3537 100644
--- a/evil-commands.el
+++ b/evil-commands.el
@@ -1893,6 +1893,63 @@ but doesn't insert or remove any spaces."
(line-beginning-position count-num))))
(funcall join-fn beg-adjusted end-adjusted)))))))
+(defun evil--ex-string-for-print (beg end linump)
+ "Return a string to be printed by :print etc.
+Starts at line of BEG and end at line of END.
+Includes line number at beginning of each line if LINUMP is non-nil."
+ (let ((result-string "")
+ (continue t))
+ (save-excursion
+ (goto-char beg)
+ (while continue
+ (when linump
+ (setq result-string
+ (concat result-string
+ (propertize (number-to-string (line-number-at-pos))
+ 'face 'line-number-current-line)
+ " ")))
+ (setq result-string (concat result-string
+ (thing-at-point 'line)))
+ (when (or (= (point) (progn (evil-line-move 1 t) (point)))
+ (> (line-end-position) end))
+ (setq continue nil))))
+ (setq result-string (string-trim-right result-string "\n"))
+ result-string))
+
+(defun evil--ex-print (beg end count linump)
+ "Print lines in range to the echo area.
+Starting at BEG and ending at END + COUNT lines.
+Include line number at the start of each line if LINUMP is non-nil."
+ (let* ((count (if count (string-to-number count) 1))
+ (end (save-excursion (goto-char (if (= (point-max) end) end (1- end)))
+ (line-end-position count)))
+ (substring (evil--ex-string-for-print beg end linump)))
+ (cond ((> 1 count) (user-error "Positive count required"))
+ (evil--ex-global-active-p
+ (setq evil--ex-print-accumulator
+ (if (string= "" evil--ex-print-accumulator)
+ (concat evil--ex-print-accumulator substring)
+ (concat evil--ex-print-accumulator "\n" substring))))
+ (t (message "%s" substring)
+ (when (string-match-p "\n" substring)
+ (goto-char end)
+ (evil-beginning-of-line))))))
+
+(defun evil--echo-global-print+clear ()
+ "Print accumulated print output from :global print, and clear."
+ (message "%s" evil--ex-print-accumulator)
+ (setq evil--ex-print-accumulator ""))
+
+(add-hook 'evil-after-global-hook #'evil--echo-global-print+clear)
+
+(evil-define-command evil-ex-print (beg end &optional count)
+ (interactive "<r><a>")
+ (evil--ex-print beg end count nil))
+
+(evil-define-command evil-ex-numbered-print (beg end &optional count)
+ (interactive "<r><a>")
+ (evil--ex-print beg end count t))
+
(evil-define-operator evil-fill (beg end)
"Fill text."
:move-point nil
@@ -4177,13 +4234,18 @@ Use `evil-flush-lines' if INVERT is nil, or
`evil-keep-lines' if not."
(forward-line))
(setq markers (nreverse markers))
(unwind-protect
+ (progn
+ (setq evil--ex-global-active-p t)
+ (dolist (marker markers)
+ (goto-char marker)
+ (eval command-form)))
+ (progn
+ ;; ensure that all markers are deleted afterwards,
+ ;; even in the event of failure
(dolist (marker markers)
- (goto-char marker)
- (eval command-form))
- ;; ensure that all markers are deleted afterwards,
- ;; even in the event of failure
- (dolist (marker markers)
- (set-marker marker nil))))))))
+ (set-marker marker nil))
+ (run-hooks 'evil-after-global-hook)
+ (setq evil--ex-global-active-p nil))))))))
(evil-define-operator evil-ex-global-inverted
(beg end pattern command &optional invert)
diff --git a/evil-ex.el b/evil-ex.el
index 81b7dd52a5..d1e3f42663 100644
--- a/evil-ex.el
+++ b/evil-ex.el
@@ -59,7 +59,7 @@
number)
(command #'evil-ex-parse-command)
(binding
- "[~&*@<>=:]+\\|[[:alpha:]_]+\\|!")
+ "[~&*@<>=:#]+\\|[[:alpha:]_]+\\|!")
(emacs-binding
"[[:alpha:]-][[:alnum:][:punct:]]*")
(argument
diff --git a/evil-maps.el b/evil-maps.el
index bdd305532d..3e44c7e8f0 100644
--- a/evil-maps.el
+++ b/evil-maps.el
@@ -577,6 +577,9 @@ included in `evil-insert-state-bindings' by default."
(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)
+(evil-ex-define-cmd "p[rint]" 'evil-ex-print)
+(evil-ex-define-cmd "nu[mber]" 'evil-ex-numbered-print)
+(evil-ex-define-cmd "#" 'evil-ex-numbered-print)
(when (featurep 'tab-bar)
(evil-ex-define-cmd "tabnew" 'tab-bar-new-tab)
diff --git a/evil-vars.el b/evil-vars.el
index 2b833d1150..df1b413a1b 100644
--- a/evil-vars.el
+++ b/evil-vars.el
@@ -36,9 +36,12 @@
(defvar evil-after-load-hook nil
"Functions to be run when loading of Evil is finished.
-This hook can be used the execute some initialization routines
+This hook can be used to execute some initialization routines
when Evil is completely loaded.")
+(defvar evil-after-global-hook nil
+ "Functions to be run after :global and :vglobal.")
+
(defcustom evil-goto-definition-functions
'(evil-goto-definition-imenu
evil-goto-definition-semantic
@@ -1221,6 +1224,13 @@ be extended to contain full lines."
:group 'evil
:type 'boolean)
+(defvar evil--ex-global-active-p nil
+ "If the :global command is running.
+Used to change the behaviour of certain commands like :print.")
+
+(defvar evil--ex-print-accumulator ""
+ "Used by :print etc. to accumulate a string when invoked by :global etc.")
+
;; Searching
(defcustom evil-symbol-word-search nil
"If nil then * and # search for words otherwise for symbols."