Skip to content

Commit

Permalink
Add evil-scroll-end-column & evil-scroll-start-column
Browse files Browse the repository at this point in the history
  • Loading branch information
tomdl89 committed Jan 14, 2023
1 parent 30e819d commit 00bd297
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
26 changes: 26 additions & 0 deletions evil-commands.el
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,32 @@ or line COUNT to the bottom of the window."
(evil-with-hproject-point-on-window
(scroll-left count)))

(evil-define-command evil-scroll-end-column ()
"Scroll the window to position the cursor at the end (right side) of the screen.
Warn if `hscroll-margin' > 0, as cursor will be `hscroll-margin' chars from
the right edge."
:repeat nil
:keep-visual t
(interactive)
(let* ((window-hpos (- (current-column) (window-hscroll)))
(dist-from-right-edge (- (window-width) window-hpos)))
(when (< 0 hscroll-margin)
(message "%s: hscroll-margin = %d" this-command hscroll-margin))
(evil-scroll-column-left (- dist-from-right-edge (abs (* 2 hscroll-margin))))))

(evil-define-command evil-scroll-start-column ()
"Scroll the window to position the cursor at the start (left side) of the screen.
Warn if `hscroll-margin' > 0, as cursor will be `hscroll-margin' chars from
the left edge."
:repeat nil
:keep-visual t
(interactive)
(let ((initial-column (current-column))
(initial-hscroll (window-hscroll)))
(when (< 0 hscroll-margin)
(message "%s: hscroll-margin = %d" this-command hscroll-margin))
(evil-scroll-column-right (- initial-column initial-hscroll hscroll-margin 1))))

;;; Text objects

;; Text objects are defined with `evil-define-text-object'. In Visual
Expand Down
2 changes: 2 additions & 0 deletions evil-maps.el
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@
(define-key evil-motion-state-map [?z right] 'evil-scroll-column-right)
(define-key evil-motion-state-map "zh" 'evil-scroll-column-left)
(define-key evil-motion-state-map [?z left] 'evil-scroll-column-left)
(define-key evil-motion-state-map "ze" 'evil-scroll-end-column)
(define-key evil-motion-state-map "zs" 'evil-scroll-start-column)
(define-key evil-motion-state-map
(read-kbd-macro evil-toggle-key) 'evil-emacs-state)

Expand Down

0 comments on commit 00bd297

Please # to comment.