Skip to content

Commit

Permalink
Small cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
axelf4 committed Apr 30, 2024
1 parent b6629ae commit 55f29f0
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 63 deletions.
45 changes: 17 additions & 28 deletions evil-commands.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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."
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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."
Expand Down
36 changes: 14 additions & 22 deletions evil-common.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 7 additions & 10 deletions evil-macros.el
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
2 changes: 1 addition & 1 deletion evil-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 1 addition & 2 deletions evil-types.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 55f29f0

Please sign in to comment.