* Point at beginning of search pattern incompatible with M-p
@ 2012-10-06 9:04 Sebastien Vauban
2012-10-06 17:31 ` Juri Linkov
0 siblings, 1 reply; 2+ messages in thread
From: Sebastien Vauban @ 2012-10-06 9:04 UTC (permalink / raw)
To: emacs-devel-mXXj517/zsQ
Hello,
I had, for some time, the following code in my .emacs.
The goal: always exit searches at the beginning of the expression found.
--8<---------------cut here---------------start------------->8---
(add-hook 'isearch-mode-end-hook 'custom-goto-match-beginning)
(defun custom-goto-match-beginning ()
"Use with isearch hook to end search at first char of match."
(when isearch-forward (goto-char isearch-other-end)))
--8<---------------cut here---------------end--------------->8---
Problem: when I want to reuse earlier search strings (with the command `M-p'),
I get the following error:
--8<---------------cut here---------------start------------->8---
Debugger entered--Lisp error: (wrong-type-argument integer-or-marker-p nil)
goto-char(nil)
(progn (goto-char isearch-other-end))
(if isearch-forward (progn (goto-char isearch-other-end)))
(when isearch-forward (goto-char isearch-other-end))
custom-goto-match-beginning()
run-hooks(isearch-mode-end-hook)
isearch-done(t t)
byte-code(...)
byte-code(...)
isearch-edit-string()
isearch-ring-adjust(nil)
isearch-ring-retreat()
call-interactively(isearch-ring-retreat nil nil)
--8<---------------cut here---------------end--------------->8---
Can this be fixed somehow, to enjoy both features (exiting searches at the
beginning of the expression, and reusing earlier search strings) together?
Best regards,
Seb
--
Sebastien Vauban
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Point at beginning of search pattern incompatible with M-p
2012-10-06 9:04 Point at beginning of search pattern incompatible with M-p Sebastien Vauban
@ 2012-10-06 17:31 ` Juri Linkov
0 siblings, 0 replies; 2+ messages in thread
From: Juri Linkov @ 2012-10-06 17:31 UTC (permalink / raw)
To: Sebastien Vauban; +Cc: emacs-devel
> I had, for some time, the following code in my .emacs.
>
> The goal: always exit searches at the beginning of the expression found.
>
> (add-hook 'isearch-mode-end-hook 'custom-goto-match-beginning)
>
> (defun custom-goto-match-beginning ()
> "Use with isearch hook to end search at first char of match."
> (when isearch-forward (goto-char isearch-other-end)))
>
> Problem: when I want to reuse earlier search strings (with the command `M-p'),
> I get the following error:
> [...]
> Can this be fixed somehow, to enjoy both features (exiting searches at the
> beginning of the expression, and reusing earlier search strings) together?
I for one have this code in ~/.emacs that could help you to do what you want:
(define-key isearch-mode-map [(control return)] 'isearch-exit)
;; C-RET doesn't add the current search string to the search ring
;; and moves point to the beginning of the found search string.
(add-hook 'isearch-mode-end-hook
(lambda ()
;; Exiting isearch with C-RET
(when (eq last-input-event 'C-return)
;; Move point to the beginning of the found search string
(if (and isearch-forward isearch-other-end)
(goto-char isearch-other-end))
;; Don't add the current search string to the search ring
(if isearch-regexp
(setq regexp-search-ring (cdr regexp-search-ring))
(setq search-ring (cdr search-ring))))))
Not sure about turning this into some configurable options.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-10-06 17:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-06 9:04 Point at beginning of search pattern incompatible with M-p Sebastien Vauban
2012-10-06 17:31 ` Juri Linkov
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.