[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/el-search b830be5 263/332: [el-search] Some scrolling t
From: |
Stefan Monnier |
Subject: |
[elpa] externals/el-search b830be5 263/332: [el-search] Some scrolling tweaks |
Date: |
Tue, 1 Dec 2020 15:49:00 -0500 (EST) |
branch: externals/el-search
commit b830be5fca2d35447172985c8a3d3a71b3a1f8b0
Author: Michael Heerdegen <michael_heerdegen@web.de>
Commit: Michael Heerdegen <michael_heerdegen@web.de>
[el-search] Some scrolling tweaks
(el-search-fancy-scrolling): New user option.
(el-search--scroll-sexp-in-view): Use signed screen line counts again.
Bump version to 1.7.9.
---
el-search.el | 67 +++++++++++++++++++++++++++++++++++++++++-------------------
1 file changed, 46 insertions(+), 21 deletions(-)
diff --git a/el-search.el b/el-search.el
index a11e9d4..ff222b2 100644
--- a/el-search.el
+++ b/el-search.el
@@ -7,7 +7,7 @@
;; Created: 29 Jul 2015
;; Keywords: lisp
;; Compatibility: GNU Emacs 25
-;; Version: 1.7.8
+;; Version: 1.7.9
;; Package-Requires: ((emacs "25") (stream "2.2.4") (cl-print "1.0"))
@@ -587,6 +587,16 @@ When nil, scrolling commands deactivate the search (like
any
other command that doesn't continue el-searching)."
:type 'boolean)
+(defcustom el-search-fancy-scrolling t
+ "Whether to enable fancy scrolling in el-search.
+When active, el-search tries to scroll the selected window in a
+way to make the current match better visible. When off, only the
+default scrolling done by Emacs is used. Since el-search puts point
+at the beginning of each match, this means that the end of each match
+can still be after `window-end'. Fancy scrolling tries to make the
+whole match visible whenever possible."
+ :type 'boolean)
+
(defvar el-search-read-expression-map
(let ((map (make-sparse-keymap)))
(set-keymap-parent map read-expression-map)
@@ -2132,26 +2142,41 @@ absolute name must be matched by all of them."
"Non-nil indicates we should not remove any highlighting.")
(defun el-search--scroll-sexp-in-view (bounds)
- (let ((wheight (window-height)))
- ;; FIXME: make the following integer constants customizable,
- ;; presumably, named in analogy to the scroll- options?
- (unless (pos-visible-in-window-p
- (save-excursion (goto-char (cadr bounds))
- (line-end-position (max +3 (/ wheight 25)))))
- (condition-case nil
- (scroll-up (min
- (max
- ;; make at least sexp end + a small margin visible
- (+ (count-screen-lines (cadr bounds) (window-end))
- (max 2 (/ wheight 4)))
- ;; also try to center current sexp
- (/ (+ (count-screen-lines (window-start) (car bounds))
- (count-screen-lines (window-end) (cadr bounds)))
- 2))
- ;; but also ensure at least a small margin is left
between point and window start
- (- (count-screen-lines (car bounds) (window-start))
- 3)))
- ((beginning-of-buffer end-of-buffer) nil)))))
+ ;; Try to make the sexp bounded by BOUNDS better visible.
+ ;; This tries to scroll (cdr BOUNDS) into view when necessary, and to
+ ;; center the sexp.
+ (when el-search-fancy-scrolling
+ (let ((wheight (window-height)))
+ ;; FIXME: make the following integer constants customizable,
+ ;; presumably, named in analogy to the scroll- options?
+ (unless (pos-visible-in-window-p
+ ;; Don't adjust scrolling when the sexp is already completely
visible
+ (save-excursion (goto-char (cadr bounds))
+ (line-end-position (max +3 (/ wheight 25)))))
+ (cl-flet ((signed-screen-lines-count
+ (lambda (a b) (funcall (if (< b a) #'- #'identity )
+ (count-screen-lines a b)))))
+
+ (condition-case nil
+ (scroll-up (min
+ (max
+ ;; make at least sexp end + a small margin visible
+ (+ (signed-screen-lines-count (window-end) (cadr
bounds))
+ (max 2 (/ wheight 4)))
+
+ ;; also try to center current sexp - this is
+ ;; / l(window-start) + l(window-end) l(car
bounds) + l(cdr bounds) \
+ ;; #lines | -------------------------------,
----------------------------- |
+ ;; \ 2
2 /
+ (/ (+ (signed-screen-lines-count (window-start)
(car bounds))
+ (signed-screen-lines-count (window-end)
(cadr bounds)))
+ 2))
+
+ ;; but also ensure at least a small margin is left
between point and
+ ;; window start
+ (- (signed-screen-lines-count (window-start) (car
bounds))
+ 3)))
+ ((beginning-of-buffer end-of-buffer) nil)))))))
(defun el-search-hl-sexp (&optional bounds)
(let ((bounds (or bounds (list (point) (el-search--end-of-sexp)))))
- [elpa] externals/el-search 8d20f8a 217/332: Add face `el-search-highlight-in-prompt-face', (continued)
- [elpa] externals/el-search 8d20f8a 217/332: Add face `el-search-highlight-in-prompt-face', Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 75f94f9 218/332: Improve quit/error handling in el-search-query-replace, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search b278fb7 219/332: Update a variable when splicing mode is toggled, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 8175417 237/332: * el-search/el-search.el: More minor tweaks, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 1f81442 241/332: [el-search] Improve forward search functions, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 5c3bd4e 247/332: [el-search] Add bindings for first/last match jumping, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 3699425 246/332: [el-search] Add command 'el-search-last-buffer-match', Stefan Monnier, 2020/12/01
- [elpa] externals/el-search cf68daf 249/332: [el-search] Avoid most calls to 'scan-sexps', Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 894f8b1 254/332: [el-search] More minor tweaks, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 6c5a6b4 265/332: [el-search] Fix an infloop in el-search--search-pattern-1, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search b830be5 263/332: [el-search] Some scrolling tweaks,
Stefan Monnier <=
- [elpa] externals/el-search e60f228 267/332: [el-search] Don't try to kill modified buffers, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 34f734e 258/332: [el-search] Add special scroll commands, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search d4ad652 278/332: [el-search] Implement an explicit quit command, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search fbe70bf 284/332: [el-search] Add C-h help, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search fac5586 285/332: [el-search] Improve my last commit "Add C-h help", Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 23911d1 288/332: [el-search] Add menus, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 68fcfcd 286/332: [el-search] Include preceding comments in occur defun context, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 90062c5 290/332: Update copyrights of some packages, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 120c662 296/332: [el-search] Minibuffer pattern prompt hints part 2, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 668d049 302/332: [el-search] Add el-search-list-defined-patterns, Stefan Monnier, 2020/12/01