summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--emacs/init.el47
1 files changed, 18 insertions, 29 deletions
diff --git a/emacs/init.el b/emacs/init.el
index 8e0db1d..792397a 100644
--- a/emacs/init.el
+++ b/emacs/init.el
@@ -563,35 +563,24 @@ The misspelled word is taken from OVERLAY.  WORD is the corrected word."
 
 (global-set-key (kbd "<f5>") 'noa/insert-date-time)
 
-;; Isearch is good, but it has some rough edges.  The easiest way forward was just to use ctrlf, which fixes most of them.  But i still had some gripes with ctrlf, like that it doesn't play well with a lot of other commands and packages and the general ecosystem built around isearch.  So i've tried to fix as many of the issues as i can while keeping real isearch.
-
-;; It makes more sense to go to the start of the match, because i start searching where i want to be.
-(defun isearch-exit-at-front ()
-  "always exit isearch, at the front of search match."
-  (interactive)
-  (isearch-exit)
-  (when isearch-forward
-    (goto-char isearch-other-end)))
-(defun isearch-exit-at-end ()
-  "Always exit isearch, at the end of search match."
-  (interactive)
-  (isearch-exit)
-  (when (not isearch-forward)
-    (goto-char isearch-other-end)))
-
-;; My preferred behaviour is for the point to be at the start of the match.  Because the search is incremental, usually i won't finish typing something useful before exiting the search, but i always start searching at a place i can reason about.  However, i can't figure out how to get this to work along with isearch-mb
-
-;; (define-key isearch-mb-minibuffer-map (kbd "<return>") #'isearch-exit-at-front)
-;; (define-key isearch-mb-minibuffer-map (kbd "C-<return>") #'isearch-exit-at-end)
-;; Make isearch always quit on C-g
-(define-key isearch-mode-map (kbd "C-g") #'isearch-cancel)
-(define-key isearch-mode-map (kbd "C-o") #'isearch-occur)
-(setopt search-whitespace-regexp ".*?")
-(setopt isearch-lax-whitespace t)
-(setopt isearch-lazy-count t)
-(setopt isearch-allow-motion t)
-(setopt isearch-repeat-on-direction-change t)
-(setopt isearch-wrap-pause 'no)
+;; Improve incremental search
+(use-package isearch
+  :bind (:map isearch-mode-map
+              ("<return>" . noa/isearch-done-goto-start) ; always put point at the beginning of the match
+              ("C-g" . isearch-cancel) ; always quit on C-g
+              ("C-o" . isearch-occur))
+  :init (defun noa/isearch-done-goto-start (&optional nopush edit)
+          "End isearch at the start of the match."
+          (interactive)
+          (funcall #'isearch-done nopush edit)
+          (when isearch-forward (goto-char isearch-other-end)))
+  :custom
+  (search-whitespace-regexp ".*?")
+  (isearch-lax-whitespace t)
+  (isearch-lazy-count t)
+  (isearch-allow-motion t)
+  (isearch-repeat-on-direction-change t)
+  (isearch-wrap-pause 'no))
 
 (global-set-key (kbd "M-o") 'other-window)
 (global-set-key (kbd "C-x k") 'kill-current-buffer)