[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/topspace 565b9a4e71 006/181: - added support for wrappe
From: |
ELPA Syncer |
Subject: |
[elpa] externals/topspace 565b9a4e71 006/181: - added support for wrapped lines or visual-line-mode |
Date: |
Tue, 23 Aug 2022 12:58:28 -0400 (EDT) |
branch: externals/topspace
commit 565b9a4e711df73d6d915bb92da4b8b6d74fbe7f
Author: Trevor Pogue <poguete@mcmaster.ca>
Commit: Trevor Pogue <poguete@mcmaster.ca>
- added support for wrapped lines or visual-line-mode
- removed partial resizing support for now until it is more stable
- fixed typo in README.md
---
README.md | 2 +-
vertical-center-mode.el | 222 +++++++++++++++++++++++++-----------------------
2 files changed, 119 insertions(+), 105 deletions(-)
diff --git a/README.md b/README.md
index 3e3ee3cc03..beab3b343d 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
### An Emacs minor-mode
Automatically center buffers vertically in the window after opening files and
during editing. Users can also adjust the centering offset with scrolling to
further scroll up or down by any amount **above** the top lines in a buffer.
-Scrolling is currently supported when using the
`scroll-down-line`/`scroll-up-line`, or
`evil-scroll-line-up`/`evil-scroll-line-down`.
+Scrolling is currently supported when using
`scroll-down-line`/`scroll-up-line`, or
`evil-scroll-line-up`/`evil-scroll-line-down`.
Scrolling also integrates well with `centered-cursor-mode`, allowing the
cursor to stay centered all the way to the top line when moving the cursor with
`previous-line` and `next-line`.
diff --git a/vertical-center-mode.el b/vertical-center-mode.el
index b34cb773aa..f594232f38 100644
--- a/vertical-center-mode.el
+++ b/vertical-center-mode.el
@@ -24,7 +24,7 @@
;;; TODO:
;; - support scrolling above top line with page scrolling as well
-;; - wrapped lines being counted as single lines when centering
+;; - centered-cursor-mode todo: isearch top centering
;; - cannot scroll above top line if buffer open in multiple windows and
;; one or more windows is scrolled above beginning of buffer
;; - recentering on window resize only occurs in selected buffer
@@ -37,65 +37,68 @@
;;;###autoload
(define-global-minor-mode global-vertical-center-mode vertical-center-mode
- vcm--turn-on-from-global)
+ vcm--turn-on-from-global)
(defun vcm--turn-on-from-global ()
- "Try to turn on vertical-center-mode from global call.
+ "Try to turn on vertical-center-mode from global call.
Called when calling command `global-vertical-center-mode'.
vertical-center-mode will not start in minibuffer or hidden buffers, or helm."
- (unless (or (bound-and-true-p vcm-on)
- (string-match " \\*.*\\*" (buffer-name))
- (string-match "helm" (buffer-name))
- (minibufferp))
- (vertical-center-mode 1)))
+ (unless (or (bound-and-true-p vcm-on)
+
(string-match " \\*.*\\*" (buffer-name))
+
(string-match "helm" (buffer-name))
+
(minibufferp))
+ (vertical-center-mode 1)))
;;;###autoload
(define-minor-mode vertical-center-mode
- "Allows vertical padding or scrolling above the top line of a buffer.
+ "Allows vertical padding or scrolling above the top line of a
buffer.
When opening a buffer, the contents are initially vertically centered with
respect to the window height. The user can also scroll as well to adjust the
centering offset. The buffer also recenters if transfered to
another window unless user has previously adjusted its height with scrolling.
"
- :init-value nil
- :ligher " vc"
- :keymap nil
- ;; only turn on if mode was previously off
- (if (and vertical-center-mode (not (bound-and-true-p vcm-on)))
- (vcm--turn-on))
- ;; only turn off if mode was previously on
- (if (and (not vertical-center-mode) (bound-and-true-p vcm-on))
- (vcm--turn-off)))
+ :init-value nil
+ :ligher " vc"
+ :keymap nil
+ ;; only turn on if mode was previously off
+ (if (and vertical-center-mode (not (bound-and-true-p vcm-on)))
+ (vcm--turn-on))
+ ;; only turn off if mode was previously on
+ (if (and (not vertical-center-mode) (bound-and-true-p vcm-on))
+ (vcm--turn-off)))
(defun vcm--turn-on ()
- (setq-local vcm-on t)
- (setq-local vcm-overlay (make-overlay (point-min) (point-max)))
- ;; vcm-scroll-offset: the overlay portion that the user adjusts with
scrolling
- (setq-local vcm-scroll-offset 0)
- (setq-local vcm-user-scrolled nil)
- (vcm--add-hooks)
- (if (not (boundp 'vcm-first-recenter-done))
- ;; vcm-first-recenter-done is used to block too many recenterings
occuring
- ;; that are triggered by window-based hooks,
- (setq-local vcm-first-recenter-done nil))
- ;; Below: let user turn the mode off then on again to recenter while
preventing
- ;; recentering here on initial mode turn-on. This avoids a bug with buffer
- ;; not being centered on emacs startup, but need to investigate further to
- ;; understand the root cause behind this bug/solution relationship.
- (if vcm-first-recenter-done (vcm--recenter-reset-scroll)))
+ (setq-local vcm-on t)
+ (setq-local vcm-overlay (make-overlay (point-min) (point-max)))
+ (setq-local vcm-scroll-offset 0)
+ (setq-local vcm-user-scrolled nil)
+ (vcm--set-prev-buffer-lines)
+ (vcm--add-hooks)
+ (if (not (boundp 'vcm-first-recenter-done))
+ ;; vcm-first-recenter-done is
used to block too many recenterings occuring
+ ;; that are triggered by
window-based hooks,
+ (setq-local
vcm-first-recenter-done nil))
+ ;; Below: let user turn the mode off then on again to recenter
while preventing
+ ;; recentering here on initial mode turn-on. This avoids a bug
with buffer
+ ;; not being centered on emacs startup, but need to investigate
further to
+ ;; understand the root cause behind this bug/solution
relationship.
+ (if vcm-first-recenter-done (vcm--recenter-reset-scroll)))
(defun vcm--turn-off ()
- "Delete/unset data structures when the mode is turned off."
- (vcm--remove-hooks)
- (makunbound 'vcm-on)
- (delete-overlay vcm-overlay)
- (makunbound 'vcm-overlay)
- (makunbound 'vcm-scroll-offset)
- (makunbound 'vcm-user-scrolled))
+ "Delete/unset data structures when the mode is turned off."
+ (vcm--remove-hooks)
+ (makunbound 'vcm-on)
+ (delete-overlay vcm-overlay)
+ (makunbound 'vcm-overlay)
+ (makunbound 'vcm-scroll-offset)
+ (makunbound 'vcm-user-scrolled)
+ (makunbound 'vcm-prev-buf-size)
+ (makunbound 'vcm-buffer-lines)
+ )
(defun vcm--kill-buffer ()
- (makunbound 'vcm-first-recenter-done)
- (vcm--turn-off))
+ (makunbound 'vcm-first-recenter-done)
+ (vcm--turn-off))
(provide 'vertical-center-mode)
@@ -104,35 +107,43 @@ another window unless user has previously adjusted its
height with scrolling.
;;; Properties (inspired specifically by definition of properties from Python)
(defun vcm--center-offset ()
- "Portion of the overlay that makes small buffers centered."
- ;; dividing by slightly less than 2 here made buffers more dead centered
- (let ((center-offset (/ (* (- (window-height) (vcm--buf-size)) 31) 64)))
- (when (< center-offset 0) (setq center-offset 0))
- center-offset)) ; return center-offset
+ "Portion of the overlay that makes small buffers centered."
+ (if (not (boundp 'vcm-buffer-lines)) (vcm--update-buffer-lines))
+ ;; dividing by slightly less than 2 here made buffers more dead
centered
+ (let ((center-offset (/ (* (- (vcm--window-lines)
vcm-buffer-lines
+
) 31) 64)))
+ (when (< center-offset 0) (setq center-offset
0))
+ center-offset))
(defun vcm--add-to-scroll-offset (direction)
- (let ((pos (+ (- (line-number-at-pos) (vcm--top-line)) (vcm--overlay-size)))
- (bottom (- (window-height) 5)))
- ;; avoids a bug with cursor suddenly scrolling up
- (when (> pos bottom) (previous-line)))
- ;; only put overlay when top line is 1
- (when (= (vcm--top-line) 1)
- ;; block scrolling text fully below bottom of window
- (unless (and (> direction 0)
- (>= (vcm--overlay-size) (- (window-height) 5)))
- (setq vcm-scroll-offset (+ vcm-scroll-offset direction)))))
+ (let ((pos (+ (- (line-number-at-pos) (vcm--top-line))
(vcm--overlay-size)))
+ (bottom (-
(vcm--window-lines) 5)))
+ ;; avoids a bug with cursor suddenly scrolling
up
+ (when (> pos bottom) (previous-line)))
+ ;; only put overlay when top line is 1
+ (when (= (vcm--top-line) 1)
+ ;; block scrolling text fully below bottom of
window
+ (unless (and (> direction 0)
+
(>= (vcm--overlay-size)
(- (vcm--window-lines) 5)))
+ (setq vcm-scroll-offset (+
vcm-scroll-offset direction)))))
(defun vcm--overlay-size ()
- "The total overlay size."
- (+ vcm-scroll-offset (vcm--center-offset)))
+ "The total overlay size."
+ (+ vcm-scroll-offset (vcm--center-offset)))
-(defun vcm--buf-size ()
- "Size of the buffer text in lines."
- (count-lines (point-min) (point-max)))
+(defun vcm--set-prev-buffer-lines (&optional arg0 arg1 arg2)
+ "Size of the buffer text in lines."
+ (setq-local vcm-prev-buf-size (count-screen-lines (point-min)
(point-max))))
(defun vcm--top-line ()
- "Line number of the top line of text shown in the window."
- (line-number-at-pos (window-start)))
+ "Line number of the top line of text shown in the window."
+ (line-number-at-pos (window-start)))
+
+(defun vcm--update-buffer-lines ()
+ (setq-local vcm-buffer-lines (count-screen-lines (point-min)
(point-max))))
+
+(defun vcm--window-lines ()
+ (floor (window-screen-lines)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -141,69 +152,72 @@ another window unless user has previously adjusted its
height with scrolling.
;; the optional unused args in this section are just for hook compatibility
(defun vcm--recenter-keep-scroll (&optional arg0 arg1 arg2)
- "Use an overlay to display empty lines at the beginning of the buffer.
+ "Use an overlay to display empty lines at the beginning of the
buffer.
This emulates the ability to scroll above the top line."
- (let ((overlay-size (vcm--overlay-size)))
- (overlay-put vcm-overlay 'before-string
- (when (> overlay-size 0) (make-string overlay-size ?\n))))
- (setq vcm-first-recenter-done t))
+ (let ((overlay-size (vcm--overlay-size)))
+ (overlay-put vcm-overlay 'before-string
+
(when (> overlay-size
0) (make-string overlay-size ?\n))))
+ (setq vcm-first-recenter-done t))
+
+(defun vcm--recenter-keep-scroll-after-change (&optional arg0 arg1 arg2)
+ (vcm--update-buffer-lines)
+ (when (not (= vcm-prev-buf-size vcm-buffer-lines))
+ (vcm--recenter-keep-scroll)))
(defun vcm--recenter-reset-scroll (&optional arg0 arg1 arg2)
- (setq vcm-scroll-offset 0)
- (vcm--recenter-keep-scroll))
+ (setq vcm-scroll-offset 0)
+ (vcm--recenter-keep-scroll))
(defun vcm--recenter-reset-scroll-conditional (&optional arg0 arg1 arg2)
- (unless (and vcm-user-scrolled) (vcm--recenter-reset-scroll)))
+ (unless vcm-user-scrolled
+ (vcm--recenter-reset-scroll)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Scrolling hooks
(defun vcm--scroll (scroll-list ccm-list scroll-direction)
- "Emulate scrolling if user command was a scrolling command."
- (when (member this-command '(comment-line))
- ;; this resolves a bug with the overlay changing size when commenting code
- (vcm--recenter-keep-scroll))
- (let ((user-is-scrolling (member this-command scroll-list))
- (centering-cursor (member this-command ccm-list)))
- ;; shouldn't scroll from moving cursor unless in centered-cursor-mode
- (unless (bound-and-true-p centered-cursor-mode) (setq centering-cursor
nil))
- (when (or user-is-scrolling centering-cursor)
- (vcm--add-to-scroll-offset scroll-direction)
- (setq vcm-user-scrolled t)
- (vcm--recenter-keep-scroll))))
+ "Emulate scrolling if user command was a scrolling command."
+ (let ((user-is-scrolling (member this-command scroll-list))
+
(centering-cursor (member this-command ccm-list)))
+ ;; shouldn't scroll from moving cursor unless
in centered-cursor-mode
+ (unless (bound-and-true-p centered-cursor-mode)
(setq centering-cursor nil))
+ (when (or user-is-scrolling centering-cursor)
+ (vcm--add-to-scroll-offset
scroll-direction)
+ (setq vcm-user-scrolled t)
+ (vcm--recenter-keep-scroll))))
(defun vcm--scroll-increase-overlay ()
- "Check if user command should initiate scrolling down."
- (vcm--scroll '(scroll-down-line evil-scroll-line-up)
- '(previous-line evil-previous-visual-line) 1))
+ "Check if user command should initiate scrolling down."
+ (vcm--scroll '(scroll-down-line evil-scroll-line-up)
+
'(previous-line
evil-previous-visual-line) 1))
(defun vcm--scroll-decrease-overlay ()
- "Check if user command should initiate scrolling up."
- (vcm--scroll '(scroll-up-line evil-scroll-line-down)
- '(next-line evil-next-visual-line) -1))
+ "Check if user command should initiate scrolling up."
+ (vcm--scroll '(scroll-up-line evil-scroll-line-down)
+
'(next-line evil-next-visual-line) -1))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Hooks
(defvar vcm--hook-alist
- '(
- (window-configuration-change-hook . vcm--recenter-reset-scroll-conditional)
- (window-size-change-functions . vcm--recenter-reset-scroll)
- (kill-buffer-hook . vcm--kill-buffer)
- (after-change-functions . vcm--recenter-keep-scroll)
- (pre-command-hook . vcm--scroll-increase-overlay)
- (post-command-hook . vcm--scroll-decrease-overlay))
- "A list of hooks so they only need to be written in one spot.
+ '(
+ (window-configuration-change-hook .
vcm--recenter-reset-scroll-conditional)
+ (kill-buffer-hook . vcm--kill-buffer)
+ (before-change-functions .
vcm--set-prev-buffer-lines)
+ (after-change-functions .
vcm--recenter-keep-scroll-after-change)
+ (pre-command-hook .
vcm--scroll-increase-overlay)
+ (post-command-hook .
vcm--scroll-decrease-overlay))
+ "A list of hooks so they only need to be written in one spot.
List of cons cells in format (hook-variable . function).")
(defun vcm--add-hooks ()
- "Add hooks defined in variable `vcm-hook-alist'."
- (mapc (lambda (entry) (add-hook (car entry) (cdr entry) t t))
- vcm--hook-alist))
+ "Add hooks defined in variable `vcm-hook-alist'."
+ (mapc (lambda (entry) (add-hook (car entry) (cdr entry) t t))
+
vcm--hook-alist))
(defun vcm--remove-hooks ()
- "Remove hooks defined in variable `vcm-hook-alist'."
- (mapc (lambda (entry) (remove-hook (car entry) (cdr entry) t))
- vcm--hook-alist))
+ "Remove hooks defined in variable `vcm-hook-alist'."
+ (mapc (lambda (entry) (remove-hook (car entry) (cdr entry) t))
+
vcm--hook-alist))
- [elpa] externals/topspace accc2a1ad0 164/181: Update NEWS.md, (continued)
- [elpa] externals/topspace accc2a1ad0 164/181: Update NEWS.md, ELPA Syncer, 2022/08/23
- [elpa] externals/topspace a1719f296b 165/181: Force update of NEWS.md, ELPA Syncer, 2022/08/23
- [elpa] externals/topspace fa2e5713d7 156/181: Update Changelog, ELPA Syncer, 2022/08/23
- [elpa] externals/topspace e046ab3a50 157/181: Internal refactoring and performance optimizations, ELPA Syncer, 2022/08/23
- [elpa] externals/topspace 27301e8c5a 171/181: Update tests, ELPA Syncer, 2022/08/23
- [elpa] externals/topspace a3e7d6ce73 174/181: Update description, ELPA Syncer, 2022/08/23
- [elpa] externals/topspace 86efd067c8 175/181: Update description, ELPA Syncer, 2022/08/23
- [elpa] externals/topspace fa67b67e1a 181/181: Update NEWS.md, ELPA Syncer, 2022/08/23
- [elpa] externals/topspace b397dd8a18 177/181: Update description, ELPA Syncer, 2022/08/23
- [elpa] externals/topspace 23ad7729db 178/181: Update description, ELPA Syncer, 2022/08/23
- [elpa] externals/topspace 565b9a4e71 006/181: - added support for wrapped lines or visual-line-mode,
ELPA Syncer <=
- [elpa] externals/topspace 770de4987f 009/181: Update README.md, ELPA Syncer, 2022/08/23
- [elpa] externals/topspace f0dbb7b3ca 015/181: Make `M-x checkdoc` happy with docstrings, ELPA Syncer, 2022/08/23
- [elpa] externals/topspace 452e892635 017/181: Make topspace-enable and topspace-disable private functions, ELPA Syncer, 2022/08/23
- [elpa] externals/topspace ece749cd58 018/181: Move topspace-keymap definition to remove warning, ELPA Syncer, 2022/08/23
- [elpa] externals/topspace 1049ef1b0e 019/181: Make topspace-enable and topspace-disable private functions, ELPA Syncer, 2022/08/23
- [elpa] externals/topspace e5b65eccf9 010/181: Update and rename vertical-center-mode.el to topspace.el, ELPA Syncer, 2022/08/23
- [elpa] externals/topspace 960c5cae34 022/181: Reflect changes to customization variable docstrings, ELPA Syncer, 2022/08/23
- [elpa] externals/topspace c8161ec68e 013/181: Update topspace.el, ELPA Syncer, 2022/08/23
- [elpa] externals/topspace 164e4aa1b9 026/181: Make auto-center-buffers update buffer in Emacs 26 when mode is first turned on, ELPA Syncer, 2022/08/23
- [elpa] externals/topspace 4a69b2eb74 027/181: Fix issue when calling recenter or recenter-top-bottom interactively, ELPA Syncer, 2022/08/23