[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/xeft 2b2c8e5925 09/55: Double-buffering
From: |
ELPA Syncer |
Subject: |
[elpa] externals/xeft 2b2c8e5925 09/55: Double-buffering |
Date: |
Fri, 13 Jan 2023 23:58:36 -0500 (EST) |
branch: externals/xeft
commit 2b2c8e592575674db4e6a7b03659be41b922dd12
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
Double-buffering
* xeft.el (xeft--insert-file-excerpt):
(xeft-refresh):
---
xeft.el | 88 +++++++++++++++++++++++++++++++++++------------------------------
1 file changed, 47 insertions(+), 41 deletions(-)
diff --git a/xeft.el b/xeft.el
index 0b2bbf98c0..d59e18f774 100644
--- a/xeft.el
+++ b/xeft.el
@@ -328,16 +328,16 @@ search phrase the user typed."
(car (last (split-string search-phrase))))
title excerpt)
(with-current-buffer (xeft--work-buffer)
- (buffer-disable-undo)
+ (setq buffer-undo-list t)
;; We don’t need to cache file content, because we only insert
;; 15 results. And adding cache (with alist) is actually slower.
(insert-file-contents file nil nil nil t)
(goto-char (point-min))
(search-forward "#+TITLE: " (line-end-position) t)
- (setq title (buffer-substring-no-properties
- (point) (line-end-position)))
+ (let ((bol (point)))
+ (end-of-line)
+ (setq title (buffer-substring-no-properties bol (point))))
(when (eq title "") (setq title "no title"))
- (forward-line)
(narrow-to-region (point) (point-max))
;; Grab excerpt.
(setq excerpt (string-trim
@@ -417,53 +417,59 @@ non-nil, display all results."
(xeft-query-term
(xeft--tighten-search-phrase search-phrase)
xeft-database
- 0 (if full 2147483647 15))))
+ 0 (if full 2147483647 16))))
(list-clipped nil))
(when (and (null full) (> (length file-list) 15))
(setq file-list (cl-subseq file-list 0 15)
list-clipped t))
+ ;; We do a double-buffering: first insert in a temp buffer,
+ ;; then insert the whole thing into this buffer.
(let ((inhibit-read-only t)
;; We don’t want ‘after-change-functions’ to run when we
;; refresh the buffer, because we set
;; ‘xeft--need-refresh’ in that hook.
(inhibit-modification-hooks t)
- (orig-point (point)))
- (buffer-disable-undo)
- ;; Actually insert the new content.
- (goto-char (point-min))
- (forward-line 2)
- (delete-region (point) (point-max))
- (if (while-no-input
- (let ((start (point)))
- (if file-list
- (dolist (file file-list)
- (xeft--insert-file-excerpt
- file search-phrase))
- ;; NOTE: this string is referred in
- ;; ‘xeft-create-note’.
- "Press RET to create a new note")
- (when list-clipped
- (insert
- (format
- "[Only showing the first 15 results, type %s to show all
of them]\n"
- (key-description
- (where-is-internal #'xeft-refresh-full
- xeft-mode-map t)))))
- ;; If we use (- start 2), emacs-rime cannot work.
- (put-text-property (- start 1) (point)
- 'read-only t))
- (xeft--highlight-search-phrase)
- (set-buffer-modified-p nil)
- ;; Save excursion wouldn’t work since we erased the
- ;; buffer and re-inserted contents.
- (goto-char orig-point)
- ;; Re-apply highlight.
- (xeft--highlight-file-at-point)
- (buffer-enable-undo))
- ;; If interrupted, go back.
+ (orig-point (point))
+ (new-content
+ (while-no-input
+ (with-temp-buffer
+ ;; Insert excerpts.
+ (if file-list
+ (dolist (file file-list)
+ (xeft--insert-file-excerpt
+ file search-phrase))
+ ;; NOTE: this string is referred in
+ ;; ‘xeft-create-note’.
+ "Press RET to create a new note")
+ ;; Insert clipped notice.
+ (when list-clipped
+ (insert
+ (format
+ "[Only showing the first 15 results, type %s to show
all of them]\n"
+ (key-description
+ (where-is-internal #'xeft-refresh-full
+ xeft-mode-map t)))))
+ (buffer-string)))))
+ (when (stringp new-content)
+ (setq buffer-undo-list t)
+ ;; Actually insert the new content.
+ (goto-char (point-min))
+ (forward-line 2)
+ (let ((start (point)))
+ (delete-region (point) (point-max))
+ (insert new-content)
+ ;; If we use (- start 2), emacs-rime cannot work.
+ (put-text-property (- start 1) (point) 'read-only t)
+ (xeft--highlight-search-phrase)
+ (set-buffer-modified-p nil)
+ ;; Re-apply highlight.
+ (xeft--highlight-file-at-point)
+ ;; If finished, update this variable.
+ (setq xeft--need-refresh nil)
+ ;; Save excursion wouldn’t work since we erased the
+ ;; buffer and re-inserted contents.
(goto-char orig-point)
- ;; If finished, update this variable.
- (setq xeft--need-refresh nil)))))))
+ (buffer-enable-undo))))))))
;;; Highlight matched phrases
- [elpa] externals/xeft b12a0f58ea 34/55: Factor out two faces xeft-excerpt-title and xeft-excerpt-body, (continued)
- [elpa] externals/xeft b12a0f58ea 34/55: Factor out two faces xeft-excerpt-title and xeft-excerpt-body, ELPA Syncer, 2023/01/13
- [elpa] externals/xeft 6fcc903bbb 51/55: ; * xeft.el (xeft--compile-module): Refactor., ELPA Syncer, 2023/01/13
- [elpa] externals/xeft af94f77834 07/55: * xeft-module.cc: Fix signiture, ELPA Syncer, 2023/01/13
- [elpa] externals/xeft 8a9f1e41b9 16/55: This got to fix it, ELPA Syncer, 2023/01/13
- [elpa] externals/xeft 951db71170 21/55: Fix default-extension format and add a recursive option, ELPA Syncer, 2023/01/13
- [elpa] externals/xeft f2a7dd9259 30/55: Minor layout change, ELPA Syncer, 2023/01/13
- [elpa] externals/xeft 9532c7dd17 40/55: * README.md: Add instruction for windows., ELPA Syncer, 2023/01/13
- [elpa] externals/xeft 45d975d54d 49/55: Prepare for ELPA, ELPA Syncer, 2023/01/13
- [elpa] externals/xeft 974520af0a 43/55: * Makefile (SOEXT): Fix if condition., ELPA Syncer, 2023/01/13
- [elpa] externals/xeft 11cf93d3aa 06/55: Refactor the module, ELPA Syncer, 2023/01/13
- [elpa] externals/xeft 2b2c8e5925 09/55: Double-buffering,
ELPA Syncer <=
- [elpa] externals/xeft 71d13999a7 13/55: Various fixes and improvements, ELPA Syncer, 2023/01/13
- [elpa] externals/xeft 6c94f7bdb4 18/55: * xeft.el (xeft-refresh): Fix to show the "create note" prompt., ELPA Syncer, 2023/01/13
- [elpa] externals/xeft a3050c1596 20/55: * xeft.el (xeft-ignore-extension): Explain the option more clearly., ELPA Syncer, 2023/01/13
- [elpa] externals/xeft 035ae7f3d0 22/55: * xeft.el: Update commentary about 'xeft-recursive'., ELPA Syncer, 2023/01/13
- [elpa] externals/xeft ad2d7b259d 23/55: Don't highlight short keywords., ELPA Syncer, 2023/01/13
- [elpa] externals/xeft 7646d9d254 24/55: * xeft-module.cc (copy_string): Remember to free string buffer., ELPA Syncer, 2023/01/13
- [elpa] externals/xeft 71febb833f 26/55: Improve latency, ELPA Syncer, 2023/01/13
- [elpa] externals/xeft 1c1b449d21 25/55: Add semicolon after macro, ELPA Syncer, 2023/01/13
- [elpa] externals/xeft 8b8c4bd37a 27/55: Improve README, ELPA Syncer, 2023/01/13
- [elpa] externals/xeft 2b515faf2e 29/55: * xeft-module.cc (copy_string): Fix free statement;, ELPA Syncer, 2023/01/13