[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/ztree a3e0442 14/23: Issue #59: Place cursor at the beg
From: |
Stefan Monnier |
Subject: |
[elpa] externals/ztree a3e0442 14/23: Issue #59: Place cursor at the beginning of the text |
Date: |
Thu, 17 Dec 2020 23:17:05 -0500 (EST) |
branch: externals/ztree
commit a3e04428ebc4a46bc31b6349c229ef16cfbd4020
Author: Alexey Veretennikov <alexey.veretennikov@gmail.com>
Commit: Alexey Veretennikov <alexey.veretennikov@gmail.com>
Issue #59: Place cursor at the beginning of the text
Implemented and tested for both ztree-dir and ztree-diff.
---
ztree-view.el | 66 ++++++++++++++++++++++-------------------------------------
1 file changed, 24 insertions(+), 42 deletions(-)
diff --git a/ztree-view.el b/ztree-view.el
index 76ae362..26493ee 100644
--- a/ztree-view.el
+++ b/ztree-view.el
@@ -133,7 +133,6 @@ the buffer is split to 2 trees")
(define-key map (kbd "x") 'ztree-toggle-expand-subtree)
(define-key map [remap next-line] 'ztree-next-line)
(define-key map [remap previous-line] 'ztree-previous-line)
-
(if window-system
(define-key map (kbd "<backspace>") 'ztree-move-up-in-tree)
(define-key map "\177" 'ztree-move-up-in-tree))
@@ -189,14 +188,23 @@ the buffer is split to 2 trees")
(defun ztree-scroll-to-line (line)
"Set the cursor to specified LINE and to the text offset (if possible)."
- (goto-char (point-min))
- (forward-line (1- line))
- (when-let (offset (plist-get
- (gethash (line-number-at-pos)
- ztree-line-tree-properties)
- 'offset))
- (beginning-of-line)
- (goto-char (+ (point) offset))))
+ (let ((cur-pos (current-column))
+ (center (/ (window-width) 2))
+ (cur-line (line-number-at-pos)))
+ ;; based on dired-next-line
+ ;; set line-move to move by logical lines
+ (let ((line-move-visual)
+ (goal-column))
+ (line-move (- line cur-line) t)
+ (when-let (offset (plist-get
+ (gethash (line-number-at-pos)
+ ztree-line-tree-properties)
+ 'offset))
+ (when (and ztree-node-side-fun
+ (>= (current-column) center))
+ (incf offset (1+ center)))
+ (beginning-of-line)
+ (goto-char (+ (point) offset))))))
(defun ztree-find-node-in-line (line)
@@ -654,8 +662,6 @@ Returns the position where the text starts."
(let ((count-str (format " [%d]" count-children)))
(insert (propertize count-str 'font-lock-face
ztreep-node-count-children-face)))))
result))
-
-
(defun ztree-jump-side ()
@@ -663,12 +669,11 @@ Returns the position where the text starts."
(interactive)
(when ztree-node-side-fun ; 2-sided tree
(let ((center (/ (window-width) 2)))
- (cond ((< (current-column) center)
- (move-to-column (1+ center)))
- ((> (current-column) center)
- (move-to-column 1))
- (t nil)))))
-
+ (if (< (current-column) center)
+ (move-to-column (1+ center))
+ (move-to-column 1))
+ ;; just recalculate and move to proper column
+ (ztree-scroll-to-line (line-number-at-pos)))))
(defun ztree-refresh-buffer (&optional line)
@@ -730,31 +735,8 @@ change the root node to the node specified."
(defun ztree-move-line (count)
"Move the point COUNT lines and place at the beginning of the node."
- ;; based on dired-next-line
- ;; set line-move to move by logical lines
- (let ((line-move-visual)
- (goal-column))
- (line-move count t))
- ;; We never want to move point into an invisible line.
- (while (and (invisible-p (point))
- (not (if (and count (< count 0)) (bobp) (eobp))))
- (forward-char (if (and count (< count 0)) -1 1)))
- ;; find the column position to place cursor
- (when-let (offset (plist-get
- (gethash (line-number-at-pos)
- ztree-line-tree-properties)
- 'offset))
- (if (not ztree-node-side-fun) ; one sided view
- (progn
- ;; now move the point to the beginning of the text
- (beginning-of-line)
- (goto-char (+ (point) offset)))
- (let ((center (/ (window-width) 2)))
- (cond ((< (current-column) center)
- (move-to-column 1))
- ((> (current-column) center)
- (move-to-column (1+ center)))
- (t nil))))))
+ (ztree-scroll-to-line
+ (+ count (line-number-at-pos))))
(defun ztree-view (
buffer-name
- [elpa] externals/ztree 47a6e40 03/23: Do not kill Ediff registry buffer, (continued)
- [elpa] externals/ztree 47a6e40 03/23: Do not kill Ediff registry buffer, Stefan Monnier, 2020/12/17
- [elpa] externals/ztree 3315ecd 01/23: Address #38, #39, Stefan Monnier, 2020/12/17
- [elpa] externals/ztree bf34366 04/23: Merge pull request #45 from xiongtx/ediff-restore, Stefan Monnier, 2020/12/17
- [elpa] externals/ztree 20b9c93 05/23: toggle show orphaned files, Stefan Monnier, 2020/12/17
- [elpa] externals/ztree febc2d0 06/23: Merge pull request #46 from Iurie/master, Stefan Monnier, 2020/12/17
- [elpa] externals/ztree 0e0a39d 09/23: Issue #56: Preserve line/column position on refresh, Stefan Monnier, 2020/12/17
- [elpa] externals/ztree 67a1d90 11/23: Issue #56: Dont preserve a cursor position on widen/narrow operations, Stefan Monnier, 2020/12/17
- [elpa] externals/ztree 369fd05 10/23: Issue #50: Show file permission differences, Stefan Monnier, 2020/12/17
- [elpa] externals/ztree 00d3318 12/23: Issue #59: Position curson on the beginning of the text, Stefan Monnier, 2020/12/17
- [elpa] externals/ztree 3273e1f 13/23: Issue #60: ztree-dir change Emacs default directory, Stefan Monnier, 2020/12/17
- [elpa] externals/ztree a3e0442 14/23: Issue #59: Place cursor at the beginning of the text,
Stefan Monnier <=
- [elpa] externals/ztree 2f62ba7 18/23: Issue #62: Cleared warnings, Stefan Monnier, 2020/12/17
- [elpa] externals/ztree 4879576 19/23: Issue #39: restore cursor position and window configuration, Stefan Monnier, 2020/12/17
- [elpa] externals/ztree c54425a 21/23: Updated README for issue #65., Stefan Monnier, 2020/12/17
- [elpa] externals/ztree d078daf 08/23: Issue #54: Added (optional) number of directory entries, Stefan Monnier, 2020/12/17
- [elpa] externals/ztree c5a1190 15/23: Issue #61: Error on unaccessible directory contents, Stefan Monnier, 2020/12/17
- [elpa] externals/ztree 0a5b25f 23/23: Merge pull request #68 from webzak/fix_ws_ignore, Stefan Monnier, 2020/12/17
- [elpa] externals/ztree 1ebb00c 07/23: Issue #52: Added 'd' hotkey for the ztree-dir to open dired., Stefan Monnier, 2020/12/17
- [elpa] externals/ztree 30dbda7 16/23: Issue #62, #63, Stefan Monnier, 2020/12/17
- [elpa] externals/ztree 50412fa 20/23: Issue #65: added ztree-diff-additional-options variable, Stefan Monnier, 2020/12/17
- [elpa] externals/ztree 901c3e3 22/23: support -w for different file size, Stefan Monnier, 2020/12/17