branch: externals/isearch-mb commit 8566108bf04e3f62177764c5960302d995513000 Author: Augusto Stoffel <arstof...@gmail.com> Commit: Augusto Stoffel <arstof...@gmail.com>
Many changes --- isearch-mb.el | 155 +++++++++++++++++++++++++--------------------------------- 1 file changed, 67 insertions(+), 88 deletions(-) diff --git a/isearch-mb.el b/isearch-mb.el index 94bb2c0..6bb39b9 100644 --- a/isearch-mb.el +++ b/isearch-mb.el @@ -26,130 +26,109 @@ (eval-when-compile (require 'subr-x)) +(put 'next-history-element 'isearch-mb-no-search t) +(put 'previous-history-element 'isearch-mb-no-search t) + +(defvar isearch-mb--prompt-overlay nil + "Overlay for minibuffer prompt updates.") + (defun isearch-mb--post-command-hook () - (let ((new-string (minibuffer-contents))) + (let ((inhibit-redisplay t) + (new-string (minibuffer-contents))) + ;; We never update isearch-message. If it's not empty, then + ;; Isearch itself changed the search string, and we update it. + (unless (string-empty-p isearch-message) + (setq isearch-message "" new-string isearch-string) + (delete-minibuffer-contents) + (insert isearch-string)) (unless (string= new-string isearch-string) (with-minibuffer-selected-window (setq isearch-string new-string) - (setq isearch-message new-string) (isearch-update-from-string-properties new-string) - (setq isearch-success t) ; Force isearch-search-and-update to try - (if (memq this-command '(previous-history-element - next-history-element)) + (if (get this-command 'isearch-mb-no-search) (isearch-update) - (isearch-search-and-update))))) + ;; (isearch-fallback nil nil t) + (goto-char isearch-barrier) + (setq isearch-adjusted t) + (setq isearch-success t) + (isearch-search-and-update)) + ))) (set-text-properties (minibuffer-prompt-end) (point-max) nil) (when-let ((fail-pos (isearch-fail-pos))) (add-text-properties (+ (minibuffer-prompt-end) fail-pos) (point-max) '(face isearch-fail))) - (cond (nil (message "> ā%sā" isearch-string)) - (isearch-error + (cond (isearch-error (isearch-mb--message isearch-error)) - (isearch-lazy-count-current - (isearch-mb--message (isearch-lazy-count-format t))))) + (isearch-wrapped (isearch-mb--message "Wrapped")))) (defun isearch-mb--minibuffer-setup () - (add-hook 'post-command-hook 'isearch-mb--post-command-hook) - (add-hook 'minibuffer-exit-hook 'isearch-mb--minibuffer-exit-hook)) - -(defun isearch-mb--minibuffer-exit-hook () - (remove-hook 'post-command-hook 'isearch-mb--post-command-hook) - (remove-hook 'minibuffer-exit-hook 'isearch-mb--minibuffer-exit-hook)) + (setq isearch-mb--prompt-overlay (make-overlay (point-min) (point-min) + (current-buffer) t t)) + (isearch-mb--prompt) + (add-hook 'post-command-hook 'isearch-mb--post-command-hook nil 'local)) -(defun isearch-mb--message (message) +(defun isearch-mb--message (message &rest _) (message (propertize (concat " [" message "]") 'face 'minibuffer-prompt))) -(defun isearch-mb--movement-command-advice (fn &rest args) - (when (string-empty-p (minibuffer-contents)) - ;; TODO: Use isearch-cmds if possible - (setq isearch-string (or (car (if isearch-regexp - regexp-search-ring - search-ring)) - (user-error "No previous search string"))) - (insert isearch-string)) - (let ((inhibit-redisplay t)) - (with-minibuffer-selected-window - (apply fn args)))) +(defun isearch-mb--prompt (&rest _) + (when isearch-mb--prompt-overlay + (overlay-put isearch-mb--prompt-overlay 'before-string + (concat + (isearch-lazy-count-format) + (capitalize + (isearch--describe-regexp-mode isearch-regexp-function)))))) -(defun isearch-mb-toggle-word () - (interactive) - (with-minibuffer-selected-window - (isearch-toggle-word))) +(defun isearch-mb--command-advice (fn &rest args) + (let ((inhibit-redisplay t)) + (with-minibuffer-selected-window + (apply fn args)))) (defvar isearch-mb-minibuffer-map (let ((map (make-sparse-keymap))) (set-keymap-parent map minibuffer-local-map) (define-key map (kbd "C-s") 'isearch-repeat-forward) - (define-key map (kbd "C-S-s") 'isearch-repeat-backward) + (define-key map (kbd "C-r") 'isearch-repeat-backward) (define-key map (kbd "<down>") 'isearch-repeat-forward) (define-key map (kbd "<up>") 'isearch-repeat-backward) - (define-key map (kbd "C-r") 'consult-history) - (define-key map (kbd "M-s w") 'isearch-mb-toggle-word) + (define-key map (kbd "M-s r") 'isearch-toggle-regexp) + (define-key map (kbd "M-s c") 'isearch-toggle-case-fold) + (define-key map (kbd "M-s w") 'isearch-toggle-word) (define-key map (kbd "M-<") 'isearch-beginning-of-buffer) (define-key map (kbd "M->") 'isearch-end-of-buffer) map)) -(defun isearch-mb-semiflex-regexp (string &optional lax) - "Return a regexp which matches the words of STRING." - (let ((words (split-string-and-unquote string))) - (mapconcat 'regexp-quote words ".*?"))) - -(isearch-define-mode-toggle semiflex "f" isearch-mb-semiflex-regexp "\ -Turning on word search turns off regexp mode.") - -(defun isearch-mb-regexp-regexp (string &optional lax) - "Return a regexp which matches the words of STRING." - string) - -(isearch-define-mode-toggle regexp "r" isearch-mb-regexp-regexp "\ -Turning on word search turns off regexp mode.") - -(defun isearch-mb-plain-regexp (string &optional lax) - "Return a regexp which matches the words of STRING." - (regexp-quote string)) - -(isearch-define-mode-toggle plain "p" isearch-mb-plain-regexp "\ -Turning on word search turns off regexp mode.") - (defun isearch-mb--isearch-mode-advice (fn &rest args) "Advice to make `isearch-mode' read from the minibuffer." (interactive) (let ((isearch-mode-map nil) - (enable-recursive-minibuffers nil) - (lazy-highlight-interval nil) - (lazy-highlight-initial-delay 0) - (lazy-highlight-buffer-max-at-a-time nil) - (lazy-count-suffix-format "%s of %s") - ;; (isearch-message-function 'ignore) - ) - (when (eq t (nth 1 args)) - (setq args `(,(car args) nil nil nil 'isearch-mb-regexp-regexp))) - (when (eq t (nth 4 args)) - (setf (nth 4 args) 'word-search-regexp)) - (unwind-protect - (progn - ;(setq-local cursor-in-non-selected-windows 'always) - (setq-local cursor-type 'hollow) - (apply fn args) - (minibuffer-with-setup-hook 'isearch-mb--minibuffer-setup - (read-from-minibuffer "Search: " nil - isearch-mb-minibuffer-map - nil - nil - (thing-at-point 'symbol))) - (isearch-exit)) - (when isearch-mode (ignore-error quit (isearch-cancel))) - (kill-local-variable 'cursor-type)))) + (history-add-new-input nil)) + (unwind-protect + (progn + (apply fn args) + (minibuffer-with-setup-hook 'isearch-mb--minibuffer-setup + (read-from-minibuffer + "I-search: " nil + isearch-mb-minibuffer-map nil + (if isearch-regexp 'regexp-search-ring 'search-ring) + (if-let (thing (thing-at-point 'symbol)) + (if isearch-regexp (regexp-quote thing) thing)) + t)) + (isearch-done)) + (when isearch-mode (ignore-error quit (isearch-cancel)))))) (defvar isearch-mb--advices - '((isearch-mode :around isearch-mb--isearch-mode-advice) - (isearch-message :override ignore) - (isearch-repeat-forward :around isearch-mb--movement-command-advice) - (isearch-repeat-backward :around isearch-mb--movement-command-advice) - (isearch-beginning-of-buffer :around isearch-mb--movement-command-advice) - (isearch-end-of-buffer :around isearch-mb--movement-command-advice))) + '((isearch-mode :around isearch-mb--isearch-mode-advice) + (isearch-message :override isearch-mb--prompt) + (isearch--momentary-message :override isearch-mb--message) + (isearch-toggle-regexp :around isearch-mb--command-advice) + (isearch-toggle-case-fold :around isearch-mb--command-advice) + (isearch-toggle-word :around isearch-mb--command-advice) + (isearch-repeat-forward :around isearch-mb--command-advice) + (isearch-repeat-backward :around isearch-mb--command-advice) + (isearch-beginning-of-buffer :around isearch-mb--command-advice) + (isearch-end-of-buffer :around isearch-mb--command-advice))) ;;;###autoload (define-minor-mode isearch-mb-mode