branch: elpa/evil
commit 55f29f07e31c408931e3569066c2050c48dd882b
Author: Axel Forsman <[email protected]>
Commit: Axel Forsman <[email protected]>

    Small cleanups
---
 evil-commands.el | 45 +++++++++++++++++----------------------------
 evil-common.el   | 36 ++++++++++++++----------------------
 evil-macros.el   | 17 +++++++----------
 evil-tests.el    |  2 +-
 evil-types.el    |  3 +--
 5 files changed, 40 insertions(+), 63 deletions(-)

diff --git a/evil-commands.el b/evil-commands.el
index 5ccfce03b3..e0554e60f3 100644
--- a/evil-commands.el
+++ b/evil-commands.el
@@ -62,7 +62,7 @@ of the line or the buffer; just return nil."
    ((not crosslines)
     ;; For efficiency, narrow the buffer to the projected
     ;; movement before determining the current line
-    (evil-with-restriction (point) (+ (point) (or count 1) 1)
+    (evil-with-restriction nil (min (+ (point) (or count 1) 1) (point-max))
       (condition-case err
           (evil-narrow-to-line (forward-char count))
         (error
@@ -75,11 +75,10 @@ of the line or the buffer; just return nil."
    (t (evil-motion-loop (nil (or count 1))
         (forward-char)
         ;; don't put the cursor on a newline
-        (and (not evil-move-beyond-eol)
-             (not (evil-visual-state-p))
-             (not (evil-operator-state-p))
-             (eolp) (not (eobp)) (not (bolp))
-             (forward-char))))))
+        (or evil-move-beyond-eol
+            (evil-visual-state-p) (evil-operator-state)
+            (not (eolp)) (bolp)
+            (forward-char))))))
 
 (evil-define-motion evil-backward-char (count &optional crosslines noerror)
   "Move cursor to the left by COUNT characters.
@@ -92,7 +91,9 @@ of the line or the buffer; just return nil."
   (cond
    ((not crosslines)
     ;; Restrict movement to the current line
-    (evil-with-restriction (- (point) (or count 1)) (1+ (point))
+    (evil-with-restriction
+        (max (- (point) (or count 1)) (point-min))
+        (min (1+ (point)) (point-max))
       (condition-case err
           (evil-narrow-to-line (backward-char count))
         (error
@@ -132,29 +133,19 @@ of the line or the buffer; just return nil."
   (let ((line-move-visual t))
     (evil-line-move (- (or count 1)))))
 
-;; used for repeated commands like "dd"
+;; Used for repeated commands like "dd"
 (evil-define-motion evil-line (count)
   "Move COUNT - 1 lines down."
   :type line
   (let (line-move-visual)
-    ;; Catch bob and eob errors. These are caused when not moving
-    ;; point starting in the first or last line, respectively. In this
-    ;; case the current line should be selected.
-    (condition-case _err
-        (evil-line-move (1- (or count 1)))
-      ((beginning-of-buffer end-of-buffer)))))
+    (evil-line-move (1- (or count 1)) t)))
 
 (evil-define-motion evil-line-or-visual-line (count)
   "Move COUNT - 1 lines down."
   :type screen-line
   (let ((line-move-visual (and evil-respect-visual-line-mode
                                visual-line-mode)))
-    ;; Catch bob and eob errors. These are caused when not moving
-    ;; point starting in the first or last line, respectively. In this
-    ;; case the current line should be selected.
-    (condition-case _err
-        (evil-line-move (1- (or count 1)))
-      ((beginning-of-buffer end-of-buffer)))))
+    (evil-line-move (1- (or count 1)) t)))
 
 (evil-define-motion evil-beginning-of-line ()
   "Move the cursor to the beginning of the current line."
@@ -3402,18 +3393,16 @@ command."
       (switch-to-buffer buffer)))))
 
 (evil-define-command evil-next-buffer (&optional count)
-  "Go to the `count'-th next buffer in the buffer list."
+  "Go to the COUNTth next buffer in the buffer list."
   :repeat nil
   (interactive "p")
-  (dotimes (_ (or count 1))
-    (next-buffer)))
+  (next-buffer count))
 
 (evil-define-command evil-prev-buffer (&optional count)
-  "Go to the `count'-th prev buffer in the buffer list."
+  "Go to the COUNTth prev buffer in the buffer list."
   :repeat nil
   (interactive "p")
-  (dotimes (_ (or count 1))
-    (previous-buffer)))
+  (previous-buffer count))
 
 (evil-define-command evil-delete-buffer (buffer &optional bang)
   "Delete a buffer.
@@ -4539,14 +4528,14 @@ of the parent of the splitted window are rebalanced."
   :repeat nil
   (interactive "p")
   (evil-window-split)
-  (evil-next-buffer count))
+  (next-buffer count))
 
 (evil-define-command evil-split-prev-buffer (&optional count)
   "Split window and go to the COUNT-th prev buffer in the buffer list."
   :repeat nil
   (interactive "p")
   (evil-window-split)
-  (evil-prev-buffer count))
+  (previous-buffer count))
 
 (evil-define-command evil-window-left (count)
   "Move the cursor to new COUNT-th window left of the current one."
diff --git a/evil-common.el b/evil-common.el
index 82eaddb37a..fd259d6cea 100644
--- a/evil-common.el
+++ b/evil-common.el
@@ -917,28 +917,26 @@ so it is more compatible with Evil's notion of EOL 
tracking."
   "Restrict the buffer to BEG and END.
 BEG or END may be nil, specifying a one-sided restriction including
 `point-min' or `point-max'. See also `evil-with-restriction.'"
+  (declare (obsolete nil "1.15.0"))
   (narrow-to-region
    (if beg (max beg (point-min)) (point-min))
    (if end (min end (point-max)) (point-max))))
 
 (defmacro evil-with-restriction (beg end &rest body)
   "Execute BODY with the buffer narrowed to BEG and END.
-BEG or END may be nil as passed to `evil-narrow'; this creates
-a one-sided restriction."
-  (declare (indent 2)
-           (debug t))
+BEG or END may be nil to specify a one-sided restriction."
+  (declare (indent 2) (debug t))
   `(save-restriction
      (let ((evil-restriction-stack
             (cons (cons (point-min) (point-max)) evil-restriction-stack)))
-       (evil-narrow ,beg ,end)
+       (narrow-to-region (or ,beg (point-min)) (or ,end (point-max)))
        ,@body)))
 
 (defmacro evil-without-restriction (&rest body)
   "Execute BODY with the top-most narrowing removed.
 This works only if the previous narrowing has been generated by
 `evil-with-restriction'."
-  (declare (indent defun)
-           (debug t))
+  (declare (indent defun) (debug t))
   `(save-restriction
      (widen)
      (narrow-to-region (car (car evil-restriction-stack))
@@ -2932,8 +2930,8 @@ linewise, otherwise it is character wise."
      (objbnd
       (let ((wsend (evil-with-restriction
                        ;; restrict to current line if we do non-line selection
-                       (and (not line) (line-beginning-position))
-                       (and (not line) (line-end-position))
+                       (unless line (line-beginning-position))
+                       (unless line (line-end-position))
                      (evil-bounds-of-not-thing-at-point thing dir))))
         (cond
          (wsend
@@ -2947,11 +2945,11 @@ linewise, otherwise it is character wise."
             (setq wsend
                   (evil-with-restriction
                       ;; restrict to current line if we do non-line selection
-                      (and (not line)
-                           (if (member thing '(evil-word evil-WORD))
-                               (save-excursion (back-to-indentation) (point))
-                             (line-beginning-position)))
-                      (and (not line) (line-end-position))
+                      (unless line
+                        (if (member thing '(evil-word evil-WORD))
+                            (save-excursion (back-to-indentation) (point))
+                          (line-beginning-position)))
+                      (unless line (line-end-position))
                     (evil-bounds-of-not-thing-at-point thing (- dir))))
             (when wsend (setq other wsend addcurrent t)))))))
      ;; current match is whitespace, add thing
@@ -3764,14 +3762,8 @@ should be left-aligned for left justification."
   (let ((fill-column position)
         adaptive-fill-mode fill-prefix)
     (evil-with-restriction
-        (save-excursion
-          (goto-char beg)
-          (line-beginning-position))
-        (save-excursion
-          (goto-char end)
-          (if (bolp)
-              (line-end-position 0)
-            (line-end-position)))
+        (save-excursion (goto-char beg) (line-beginning-position))
+        (save-excursion (goto-char end) (line-end-position (if (bolp) 0 1)))
       (goto-char (point-min))
       (while (progn
                (if (eq justify 'left)
diff --git a/evil-macros.el b/evil-macros.el
index 86eb8677b5..09b13966eb 100644
--- a/evil-macros.el
+++ b/evil-macros.el
@@ -172,21 +172,18 @@ the beginning or end of the current line."
      (when (save-excursion (goto-char end) (bolp))
        (setq end (max beg (1- end))))
      ;; Do not include the newline in Normal state
-     (and (not evil-move-beyond-eol)
-          (not (evil-visual-state-p))
-          (not (evil-operator-state-p))
-          (setq end (max beg (1- end))))
+     (or evil-move-beyond-eol
+         (evil-visual-state-p) (evil-operator-state-p)
+         (setq end (max beg (1- end))))
      (evil-with-restriction beg end
        (condition-case err
            (progn ,@body)
          (beginning-of-buffer
-          (if (= (point-min) beg)
-              (signal 'beginning-of-line nil)
-            (signal (car err) (cdr err))))
+          (signal (if (= (point-min) beg) 'beginning-of-line (car err))
+                  (cdr err)))
          (end-of-buffer
-          (if (= (point-max) end)
-              (signal 'end-of-line nil)
-            (signal (car err) (cdr err))))))))
+          (signal (if (= (point-max) end) 'end-of-line (car err))
+                  (cdr err)))))))
 
 (defun evil-eobp (&optional pos)
   "Whether point is at end-of-buffer with regard to end-of-line."
diff --git a/evil-tests.el b/evil-tests.el
index 9b4c53e79a..89bc49773a 100644
--- a/evil-tests.el
+++ b/evil-tests.el
@@ -9005,7 +9005,7 @@ Source
 
 (ert-deftest evil-test-ex-sort ()
   :tags '(evil ex)
-  "Text ex command :sort `evil-ex-sort`."
+  "Text Ex command \":sort\" (`evil-ex-sort')."
   (ert-info ("Plain sort")
     (evil-test-buffer
       "[z]zyy\ntest\ntEst\ntesT\nTEST\ntest\n"
diff --git a/evil-types.el b/evil-types.el
index 395dc2fa6b..67ea9ce161 100644
--- a/evil-types.el
+++ b/evil-types.el
@@ -138,8 +138,7 @@ and will be removed in a future version."
 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))
+            (if (not (and evil-respect-visual-line-mode visual-line-mode))
                 (evil-line-expand beg end)
               (evil-range
                (progn

Reply via email to