emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/evil 4d0088dc66: Small cleanups


From: ELPA Syncer
Subject: [nongnu] elpa/evil 4d0088dc66: Small cleanups
Date: Sun, 25 Jun 2023 13:00:27 -0400 (EDT)

branch: elpa/evil
commit 4d0088dc669be6e06cf25340f8935db5eaca2a81
Author: Axel Forsman <axelsfor@gmail.com>
Commit: Axel Forsman <axelsfor@gmail.com>

    Small cleanups
    
    * Deprecate evil-loop since it is too niche, and manages makes
      evil-motion-loop less readable.
    * Use separate setq-local calls for each variable/value pair, since
      the combined form does not exist in Emacs versions <=25.3.
---
 evil-commands.el |  42 +++++++++-------------
 evil-common.el   | 105 ++++++++++++++++++++++---------------------------------
 evil-core.el     |   4 +--
 evil.el          |   1 +
 4 files changed, 61 insertions(+), 91 deletions(-)

diff --git a/evil-commands.el b/evil-commands.el
index 24fcd3390d..68e9663e4b 100644
--- a/evil-commands.el
+++ b/evil-commands.el
@@ -1978,7 +1978,7 @@ Surround line denoted by BORDERLINE with dashes if 
non-nil."
   (interactive "<r><a>")
   (evil--ex-print beg end count t))
 
-(evil-define-command evil-ex-z (_beg end &optional zmarks _bang)
+(evil-define-command evil-ex-z (beg end &optional zmarks bang)
   "Display several lines of text surrounding the line specified by range.
 BEG and END represent the range, ZMARKS represents the args in string form.
 With a count supplied in the args, display that number of lines.  Without a
@@ -2062,34 +2062,24 @@ If a `#' is included before the mark args, the lines 
are numbered."
   :move-point nil
   :type line
   (evil-ensure-column
-    ;; Reset unneeded change made by evil-ensure-column
-    (setq this-command real-this-command)
+    (setq this-command real-this-command) ; Reset change made by 
evil-ensure-column
     (save-restriction
       (narrow-to-region beg end)
-      (if (and (= beg (line-beginning-position))
-               (= end (line-beginning-position 2)))
+      (if (save-excursion (goto-char beg) (= end (line-beginning-position 2)))
           ;; since some Emacs modes can only indent one line at a time,
           ;; implement "==" as a call to `indent-according-to-mode'
           (indent-according-to-mode)
         (goto-char beg)
         (indent-region beg end))
-      ;; Update `beg' and `end'
-      (setq beg (point-min)
-            end (point-max))
-      ;; We also need to tabify or untabify the leading white characters
+      ;; Tabify or untabify leading whitespace characters
       (when evil-indent-convert-tabs
-        (let* ((beg-line (line-number-at-pos beg))
-               (end-line (line-number-at-pos end))
-               (ln beg-line)
-               (convert-white (if indent-tabs-mode 'tabify 'untabify)))
+        ;; Whether tab or space should be used is determined by 
indent-tabs-mode
+        (let ((convert-fun (if indent-tabs-mode #'tabify #'untabify)))
           (save-excursion
-            (while (<= ln end-line)
-              (goto-char (point-min))
-              (forward-line (- ln 1))
-              (back-to-indentation)
-              ;; Whether tab or space should be used is determined by 
indent-tabs-mode
-              (funcall convert-white (line-beginning-position) (point))
-              (setq ln (1+ ln)))))))))
+            (goto-char (point-min))
+            (while (not (eolp))
+              (funcall convert-fun (point) (progn (skip-chars-forward " \t") 
(point)))
+              (forward-line))))))))
 
 (evil-define-operator evil-indent-line (beg end)
   "Indent the line."
@@ -2169,7 +2159,7 @@ See also `evil-shift-left'."
   "Delete all indentation on current line."
   (interactive)
   (save-excursion
-    (evil-beginning-of-line)
+    (move-beginning-of-line nil)
     (delete-region (point) (progn (skip-chars-forward " \t") (point)))))
 
 (evil-define-command evil-shift-right-line (count)
@@ -3778,12 +3768,14 @@ If FORCE is non-nil and MARKS is blank, all local marks 
except 0-9 are removed."
                   (cl-remove-if-not (lambda (m) (<= ?0 (car m) ?9))
                                     evil-markers-alist))))))
 
-(eval-when-compile (require 'ffap))
+(declare-function ffap-file-at-point "ffap")
+(defvar ffap-string-at-point-region)
 (evil-define-command evil-find-file-at-point-with-line ()
   "Open the file at point and go to position if present.
-    Support positions in the following formats: path:line path(line) 
path:line:col and path(line,col)"
+Supports positions in the following formats: \"path:line path(line)\",
+\"path:line:col\" and \"path(line,col)\"."
   (require 'ffap)
-  (let ((fname (with-no-warnings (ffap-file-at-point))))
+  (let ((fname (ffap-file-at-point)))
     (unless fname
       (user-error "File does not exist."))
     (let* ((line-number-pattern ":\\([0-9]+\\)\\=" ) ; path:line format
@@ -3806,7 +3798,7 @@ If FORCE is non-nil and MARKS is blank, all local marks 
except 0-9 are removed."
       (message "%s, %s"
                (if line-number (format "line: %s" line-number) "no line")
                (if column-number (format "column: %s" column-number) "no 
column"))
-      (with-no-warnings (find-file-at-point fname))
+      (find-file-at-point fname)
       (when line-number
         (goto-char (point-min))
         (forward-line (1- line-number))
diff --git a/evil-common.el b/evil-common.el
index bada299825..49a5456d9c 100644
--- a/evil-common.el
+++ b/evil-common.el
@@ -48,15 +48,6 @@
 (defalias 'evil-set-selection
   (if (fboundp 'gui-set-selection) 'gui-set-selection 'x-set-selection))
 
-(defmacro evil-called-interactively-p ()
-  "Wrapper for `called-interactively-p'.
-In older versions of Emacs, `called-interactively-p' takes
-no arguments.  In Emacs 23.2 and newer, it takes one argument."
-  (called-interactively-p 'any))
-(make-obsolete 'evil-called-interactively-p
-               "please use (called-interactively-p 'any) instead."
-               "Git commit 222b791")
-
 ;; macro helper
 (eval-and-compile
   (defun evil-unquote (exp)
@@ -492,19 +483,18 @@ other gives an empty string."
 A character set is the part between [ and ] in a regular expression.
 If any character set is complemented, the result is also complemented."
   (let ((bracket "") (complement "") (hyphen "") result)
-    (save-match-data
-      (dolist (set sets)
-        (when (string-match-p "^\\^" set)
-          (setq set (substring set 1)
-                complement "^"))
-        (when (string-match-p "^]" set)
-          (setq set (substring set 1)
-                bracket "]"))
-        (when (string-match-p "^-" set)
-          (setq set (substring set 1)
-                hyphen "-"))
-        (setq result (concat result set)))
-      (format "%s%s%s%s" complement bracket hyphen result))))
+    (dolist (set sets)
+      (when (string-match-p "^\\^" set)
+        (setq set (substring set 1)
+              complement "^"))
+      (when (string-match-p "^]" set)
+        (setq set (substring set 1)
+              bracket "]"))
+      (when (string-match-p "^-" set)
+        (setq set (substring set 1)
+              hyphen "-"))
+      (setq result (concat result set)))
+    (format "%s%s%s%s" complement bracket hyphen result)))
 
 ;;; Key sequences
 
@@ -723,7 +713,7 @@ directive and nil otherwise.  FILENAME will be the extracted
 filename."
   (if (and (stringp file-or-append)
            (string-match "\\(>> *\\)" file-or-append))
-      (cons t (substring file-or-append(match-end 1)))
+      (cons t (substring file-or-append (match-end 1)))
     (cons nil file-or-append)))
 
 (defun evil-set-keymap-prompt (map prompt)
@@ -735,8 +725,7 @@ filename."
 (defun evil-lookup-key (map key)
   "Return non-nil value if KEY is bound in MAP."
   (let ((definition (lookup-key map key)))
-    (if (numberp definition) ; in-band error
-        nil
+    (unless (numberp definition) ; in-band error
       definition)))
 
 ;;; Display
@@ -996,23 +985,18 @@ Like `move-end-of-line', but retains the goal column."
 This behavior is controlled by `evil-move-beyond-eol'."
   (and (not evil-move-beyond-eol)
        (eolp)
-       (= (point)
-          (save-excursion
-            (evil-move-end-of-line)
-            (point)))
+       (= (point) (save-excursion (evil-move-end-of-line) (point)))
        (evil-move-cursor-back t)))
 
 (defun evil-move-cursor-back (&optional force)
   "Move point one character back within the current line.
 Contingent on the variable `evil-move-cursor-back' or the FORCE
 argument.  Movement is constrained to the current field."
-  (unless (or (not (or evil-move-cursor-back force))
-              (bolp)
-              (when (bound-and-true-p visual-line-mode)
-                (= (point) (save-excursion
-                             (vertical-motion 0)
-                             (point)))))
-    (goto-char (constrain-to-field (1- (point)) (point)))))
+  (or (not (or evil-move-cursor-back force))
+      (bolp)
+      (when (bound-and-true-p visual-line-mode)
+        (= (point) (save-excursion (vertical-motion 0) (point))))
+      (goto-char (constrain-to-field (1- (point)) (point)))))
 
 (defun evil-line-position (line &optional column)
   "Return the position of LINE.
@@ -1057,8 +1041,7 @@ terminates, which is 0 if the loop completes successfully.
 RESULT specifies a variable for storing this value.
 
 \(fn (VAR COUNT [RESULT]) BODY...)"
-  (declare (indent defun)
-           (debug dolist))
+  (declare (indent defun) (debug dolist) (obsolete nil "1.15.0"))
   (let* ((i (make-symbol "loopvar"))
          (var (pop spec))
          (count (pop spec))
@@ -1080,37 +1063,32 @@ RESULT specifies a variable for storing this value.
 (defmacro evil-motion-loop (spec &rest body)
   "Loop a certain number of times.
 Evaluate BODY repeatedly COUNT times with VAR bound to 1 or -1,
-depending on the sign of COUNT. RESULT, if specified, holds
-the number of unsuccessful iterations, which is 0 if the loop
-completes successfully. This is also the return value.
+depending on the sign of COUNT. Set RESULT, if specified, to the
+number of unsuccessful iterations, which is 0 if the loop completes
+successfully. This is also the return value.
 
-Each iteration must move point; if point does not change,
-the loop immediately quits. See also `evil-loop'.
+Each iteration must move point; if point does not change, the loop
+immediately quits.
 
 \(fn (VAR COUNT [RESULT]) BODY...)"
   (declare (indent defun)
            (debug ((symbolp form &optional symbolp) body)))
   (let* ((var (or (pop spec) (make-symbol "unitvar")))
-         (countval (or (pop spec) 0))
-         (result (pop spec))
-         (i (make-symbol "loopvar"))
-         (count (make-symbol "countvar"))
-         (done (make-symbol "donevar"))
-         (orig (make-symbol "origvar")))
-    `(let* ((,count ,countval)
-            (,var (if (< ,count 0) -1 1)))
-       (catch ',done
-         (evil-loop (,i ,count ,result)
-           (let ((,orig (point)))
-             ,@body
-             (when (= (point) ,orig)
-               (throw ',done ,i))))))))
+         (count (or (pop spec) 0))
+         (result (or (pop spec) var))
+         (i (make-symbol "loopvar")))
+    `(let* ((,i ,count)
+            (,var (if (< ,i 0) -1 1)))
+       (while (and (/= ,i 0)
+                   (/= (point) (progn ,@body (point))))
+         (setq ,i (if (< ,i 0) (1+ ,i) (1- ,i))))
+       (setq ,result ,i))))
 
 (defun evil-signal-at-bob-or-eob (&optional count)
   "Signal error if `point' is at boundaries.
 If `point' is at bob and COUNT is negative this function signal
-'beginning-of-buffer. If `point' is at eob and COUNT is positive
-this function singal 'end-of-buffer. This function should be used
+`beginning-of-buffer'. If `point' is at eob and COUNT is positive
+this function singal `end-of-buffer'. This function should be used
 in motions. COUNT defaults to 1."
   (setq count (or count 1))
   (cond
@@ -1118,17 +1096,17 @@ in motions. COUNT defaults to 1."
    ((> count 0) (evil-signal-at-eob))))
 
 (defun evil-signal-at-bob ()
-  "Signal 'beginning-of-buffer if `point' is at bob.
+  "Signal `beginning-of-buffer' if `point' is at bob.
 This function should be used in backward motions. If `point' is at
 bob so that no further backward motion is possible the error
-'beginning-of-buffer is raised."
+`beginning-of-buffer' is raised."
   (when (bobp) (signal 'beginning-of-buffer nil)))
 
 (defun evil-signal-at-eob ()
-  "Signal 'end-of-buffer if `point' is at eob.
+  "Signal `end-of-buffer' if `point' is at eob.
 This function should be used in forward motions. If `point' is close
 to eob so that no further forward motion is possible the error
-'end-of-buffer is raised. This is the case if `point' is at
+`end-of-buffer' is raised. This is the case if `point' is at
 `point-max' or if is one position before `point-max',
 `evil-move-beyond-eol' is nil and `point' is not at the end
 of a line. The latter is necessary because `point' cannot be
@@ -2851,7 +2829,6 @@ a property list."
 (defun evil-range-p (object)
   "Whether OBJECT is a range."
   (and (listp object)
-       (>= (length object) 2)
        (numberp (nth 0 object))
        (numberp (nth 1 object))))
 
diff --git a/evil-core.el b/evil-core.el
index b1f5fb004b..fae8bcdff0 100644
--- a/evil-core.el
+++ b/evil-core.el
@@ -120,8 +120,8 @@
         (cl-pushnew 'evil-mode-map-alist emulation-mode-map-alists)
         (evil-initialize-local-keymaps)
         (when (minibufferp)
-          (setq-local evil-default-state 'insert
-                      evil-echo-state nil))
+          (setq-local evil-default-state 'insert)
+          (setq-local evil-echo-state nil))
         (setq evil-input-method current-input-method)
         (evil-initialize-state)
         (add-hook 'input-method-activate-hook #'evil-activate-input-method t t)
diff --git a/evil.el b/evil.el
index 599bfb4ceb..dc13a828c0 100644
--- a/evil.el
+++ b/evil.el
@@ -59,6 +59,7 @@
 ;;      mailing list (see below).
 ;; Created: 2011-03-01
 ;; Version: 1.15.0
+;; Package-Requires: ((emacs "24.1") (cl-lib "0.5") (goto-chg "1.6"))
 ;; Keywords: emulations
 ;; URL: https://github.com/emacs-evil/evil
 ;;      Repository: https://github.com/emacs-evil/evil.git



reply via email to

[Prev in Thread] Current Thread [Next in Thread]