* Tiny change to find-tag-default.
@ 2006-07-21 9:53 Kim F. Storm
2006-07-21 14:18 ` Drew Adams
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: Kim F. Storm @ 2006-07-21 9:53 UTC (permalink / raw)
The following way of working seems natural to me -- but doesn't work.
[I have transient-mark-mode == t]
Suppose I'm looking at a text, and want to grep for a phrase
(e.g. just two words) in that text, I highlight the text to search for
(set mark, go to end of text) and do M-x lgrep.
However, this ignores my selection, and just suggests the word at point
at the regexp.
The following patch changes that to DTRT (IMO):
I don't think it makes sense to do this w/o transient-mark-mode,
but that's why we have temporary transient-mark-mode marking.
Index: subr.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/subr.el,v
retrieving revision 1.521
diff -b -c -r1.521 subr.el
*** subr.el 18 Jul 2006 01:34:48 -0000 1.521
--- subr.el 21 Jul 2006 09:47:53 -0000
***************
*** 1993,1998 ****
--- 1993,2001 ----
(defun find-tag-default ()
"Determine default tag to search for, based on text at point.
If there is no plausible default, return nil."
+ (if (and transient-mark-mode
+ mark-active)
+ (buffer-substring-no-properties (point) (mark))
(save-excursion
(while (looking-at "\\sw\\|\\s_")
(forward-char 1))
***************
*** 2012,2018 ****
(forward-char 1))
(point)))
(error nil)))
! nil)))
(defun play-sound (sound)
"SOUND is a list of the form `(sound KEYWORD VALUE...)'.
--- 2015,2021 ----
(forward-char 1))
(point)))
(error nil)))
! nil))))
(defun play-sound (sound)
"SOUND is a list of the form `(sound KEYWORD VALUE...)'.
--
Kim F. Storm <storm@cua.dk> http://www.cua.dk
^ permalink raw reply [flat|nested] 11+ messages in thread
* RE: Tiny change to find-tag-default.
2006-07-21 9:53 Tiny change to find-tag-default Kim F. Storm
@ 2006-07-21 14:18 ` Drew Adams
2006-07-21 22:21 ` Kim F. Storm
2006-07-22 4:39 ` Richard Stallman
2006-07-28 23:04 ` Kim F. Storm
2 siblings, 1 reply; 11+ messages in thread
From: Drew Adams @ 2006-07-21 14:18 UTC (permalink / raw)
Suppose I'm looking at a text, and want to grep for a phrase
(e.g. just two words) in that text, I highlight the text to search for
(set mark, go to end of text) and do M-x lgrep. ...
I don't think it makes sense to do this w/o transient-mark-mode,
but that's why we have temporary transient-mark-mode marking.
That behavior ounds good to me. What about doing the same for `grep' and the
other similar commands?
OTOH, if done in `find-tag-default', this would also affect things like
function-called-at-point and variable-at-point. I don't know if that would
be a good feature or not.
[Not directly related - Is there a quick way to set the region around the
last occurrence found using isearch and query-replace (even if the latter is
exited with C-g)? If so, together with your proposal that would let you
immediately move from searching in a file to grepping for the same thing in
other files.]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Tiny change to find-tag-default.
2006-07-21 14:18 ` Drew Adams
@ 2006-07-21 22:21 ` Kim F. Storm
2006-07-21 23:15 ` Drew Adams
0 siblings, 1 reply; 11+ messages in thread
From: Kim F. Storm @ 2006-07-21 22:21 UTC (permalink / raw)
Cc: emacs-devel
"Drew Adams" <drew.adams@oracle.com> writes:
> Suppose I'm looking at a text, and want to grep for a phrase
> (e.g. just two words) in that text, I highlight the text to search for
> (set mark, go to end of text) and do M-x lgrep. ...
> I don't think it makes sense to do this w/o transient-mark-mode,
> but that's why we have temporary transient-mark-mode marking.
>
> That behavior ounds good to me. What about doing the same for `grep' and the
> other similar commands?
If the change is made to find-tag-default, the change will apply to grep
and find-grep too.
>
> OTOH, if done in `find-tag-default', this would also affect things like
> function-called-at-point and variable-at-point. I don't know if that would
> be a good feature or not.
At least it still gives predictable behavior (and in most cases it doesn't matter,
as the find-tag-default is only used as a last resort fallback).
--
Kim F. Storm <storm@cua.dk> http://www.cua.dk
^ permalink raw reply [flat|nested] 11+ messages in thread
* RE: Tiny change to find-tag-default.
2006-07-21 22:21 ` Kim F. Storm
@ 2006-07-21 23:15 ` Drew Adams
0 siblings, 0 replies; 11+ messages in thread
From: Drew Adams @ 2006-07-21 23:15 UTC (permalink / raw)
> Suppose I'm looking at a text, and want to grep for a phrase
> (e.g. just two words) in that text, I highlight the text
> to search for
> (set mark, go to end of text) and do M-x lgrep. ...
> I don't think it makes sense to do this w/o transient-mark-mode,
> but that's why we have temporary transient-mark-mode marking.
>
> That behavior sounds good to me. What about doing the same for
> `grep' and the other similar commands?
If the change is made to find-tag-default, the change will apply to grep
and find-grep too.
Oh, I didn't see that; sorry. It didn't look like `grep' used it.
> OTOH, if done in `find-tag-default', this would also affect
> things like function-called-at-point and variable-at-point.
> I don't know if that would be a good feature or not.
At least it still gives predictable behavior (and in most cases
it doesn't matter,
as the find-tag-default is only used as a last resort fallback).
Right.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Tiny change to find-tag-default.
2006-07-21 9:53 Tiny change to find-tag-default Kim F. Storm
2006-07-21 14:18 ` Drew Adams
@ 2006-07-22 4:39 ` Richard Stallman
2006-07-22 12:17 ` martin rudalics
2006-07-28 23:04 ` Kim F. Storm
2 siblings, 1 reply; 11+ messages in thread
From: Richard Stallman @ 2006-07-22 4:39 UTC (permalink / raw)
Cc: emacs-devel
This seems like a nice feature. Please check two things:
1. Does it give good results with mark-even-if-inactive?
2. Does the Emacs manual need updating?
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Tiny change to find-tag-default.
2006-07-22 4:39 ` Richard Stallman
@ 2006-07-22 12:17 ` martin rudalics
2006-07-23 17:34 ` Richard Stallman
2006-07-28 0:09 ` Kim F. Storm
0 siblings, 2 replies; 11+ messages in thread
From: martin rudalics @ 2006-07-22 12:17 UTC (permalink / raw)
Cc: emacs-devel, Kim F. Storm
[-- Attachment #1: Type: text/plain, Size: 379 bytes --]
Wouldn't it make sense to rewrite the rest of `find-tag-default' too?
In its current version it unnecessarily clobbers `match-data', requires
a `condition-case' to handle errors in `forward-sexp', and has other
tedious things like repeated forward-charing and re-searching.
I'm using the attached version for approximately half a year and didn't
encounter any problems so far.
[-- Attachment #2: subr.patch --]
[-- Type: text/plain, Size: 1924 bytes --]
*** subr.el Tue Jun 6 19:20:26 2006
--- subr.el Mon Jul 10 11:42:40 2006
***************
*** 1949,1973 ****
"Determine default tag to search for, based on text at point.
If there is no plausible default, return nil."
(save-excursion
! (while (looking-at "\\sw\\|\\s_")
! (forward-char 1))
! (if (or (re-search-backward "\\sw\\|\\s_"
! (save-excursion (beginning-of-line) (point))
! t)
! (re-search-forward "\\(\\sw\\|\\s_\\)+"
! (save-excursion (end-of-line) (point))
! t))
! (progn
! (goto-char (match-end 0))
! (condition-case nil
! (buffer-substring-no-properties
! (point)
! (progn (forward-sexp -1)
! (while (looking-at "\\s'")
! (forward-char 1))
! (point)))
! (error nil)))
! nil)))
(defun play-sound (sound)
"SOUND is a list of the form `(sound KEYWORD VALUE...)'.
--- 1949,1973 ----
"Determine default tag to search for, based on text at point.
If there is no plausible default, return nil."
(save-excursion
! (let (from to bound)
! (when (or (and (save-excursion
! (skip-syntax-backward "w_") (setq from (point)))
! (save-excursion
! (skip-syntax-forward "w_") (setq to (point)))
! (> to from))
! ;; Look between `line-beginning-position' and `point'.
! (and (setq bound (line-beginning-position))
! (skip-syntax-backward "^w_" bound)
! (> (setq to (point)) bound)
! (skip-syntax-backward "w_")
! (setq from (point)))
! ;; Look between `point' and `line-end-position'.
! (and (setq bound (line-end-position))
! (skip-syntax-forward "^w_" bound)
! (< (setq from (point)) bound)
! (skip-syntax-forward "w_")
! (setq to (point))))
! (buffer-substring-no-properties from to)))))
(defun play-sound (sound)
"SOUND is a list of the form `(sound KEYWORD VALUE...)'.
[-- Attachment #3: Type: text/plain, Size: 142 bytes --]
_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Tiny change to find-tag-default.
2006-07-22 12:17 ` martin rudalics
@ 2006-07-23 17:34 ` Richard Stallman
2006-07-28 23:06 ` Kim F. Storm
2006-07-28 0:09 ` Kim F. Storm
1 sibling, 1 reply; 11+ messages in thread
From: Richard Stallman @ 2006-07-23 17:34 UTC (permalink / raw)
Cc: storm, emacs-devel
Wouldn't it make sense to rewrite the rest of `find-tag-default' too?
In its current version it unnecessarily clobbers `match-data', requires
a `condition-case' to handle errors in `forward-sexp', and has other
tedious things like repeated forward-charing and re-searching.
That isn't a core part of the system, so I see no need to reject this.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Tiny change to find-tag-default.
2006-07-22 12:17 ` martin rudalics
2006-07-23 17:34 ` Richard Stallman
@ 2006-07-28 0:09 ` Kim F. Storm
2006-07-28 9:12 ` martin rudalics
1 sibling, 1 reply; 11+ messages in thread
From: Kim F. Storm @ 2006-07-28 0:09 UTC (permalink / raw)
Cc: rms, emacs-devel
martin rudalics <rudalics@gmx.at> writes:
> Wouldn't it make sense to rewrite the rest of `find-tag-default' too?
> In its current version it unnecessarily clobbers `match-data', requires
> a `condition-case' to handle errors in `forward-sexp', and has other
> tedious things like repeated forward-charing and re-searching.
>
> I'm using the attached version for approximately half a year and didn't
> encounter any problems so far.
Your code works fine for me too.
But I'm puzzled by the use of (forward-sexp -1) in the old code. What
subtle effect did the author intend by using that? Maybe to get to
the function name in a function call? ... if that was the intention,
it doesn't seem to work.
>
> *** subr.el Tue Jun 6 19:20:26 2006
> --- subr.el Mon Jul 10 11:42:40 2006
> ***************
> *** 1949,1973 ****
> "Determine default tag to search for, based on text at point.
> If there is no plausible default, return nil."
> (save-excursion
> ! (while (looking-at "\\sw\\|\\s_")
> ! (forward-char 1))
> ! (if (or (re-search-backward "\\sw\\|\\s_"
> ! (save-excursion (beginning-of-line) (point))
> ! t)
> ! (re-search-forward "\\(\\sw\\|\\s_\\)+"
> ! (save-excursion (end-of-line) (point))
> ! t))
> ! (progn
> ! (goto-char (match-end 0))
> ! (condition-case nil
> ! (buffer-substring-no-properties
> ! (point)
> ! (progn (forward-sexp -1)
> ! (while (looking-at "\\s'")
> ! (forward-char 1))
> ! (point)))
> ! (error nil)))
> ! nil)))
>
> (defun play-sound (sound)
> "SOUND is a list of the form `(sound KEYWORD VALUE...)'.
> --- 1949,1973 ----
> "Determine default tag to search for, based on text at point.
> If there is no plausible default, return nil."
> (save-excursion
> ! (let (from to bound)
> ! (when (or (and (save-excursion
> ! (skip-syntax-backward "w_") (setq from (point)))
> ! (save-excursion
> ! (skip-syntax-forward "w_") (setq to (point)))
> ! (> to from))
> ! ;; Look between `line-beginning-position' and `point'.
> ! (and (setq bound (line-beginning-position))
> ! (skip-syntax-backward "^w_" bound)
> ! (> (setq to (point)) bound)
> ! (skip-syntax-backward "w_")
> ! (setq from (point)))
> ! ;; Look between `point' and `line-end-position'.
> ! (and (setq bound (line-end-position))
> ! (skip-syntax-forward "^w_" bound)
> ! (< (setq from (point)) bound)
> ! (skip-syntax-forward "w_")
> ! (setq to (point))))
> ! (buffer-substring-no-properties from to)))))
>
> (defun play-sound (sound)
> "SOUND is a list of the form `(sound KEYWORD VALUE...)'.
--
Kim F. Storm <storm@cua.dk> http://www.cua.dk
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Tiny change to find-tag-default.
2006-07-28 0:09 ` Kim F. Storm
@ 2006-07-28 9:12 ` martin rudalics
0 siblings, 0 replies; 11+ messages in thread
From: martin rudalics @ 2006-07-28 9:12 UTC (permalink / raw)
Cc: rms, emacs-devel
> But I'm puzzled by the use of (forward-sexp -1) in the old code. What
> subtle effect did the author intend by using that? Maybe to get to
> the function name in a function call? ... if that was the intention,
> it doesn't seem to work.
Probably someone wanted to allow `forward-sexp-function' to kick in.
I think `find-tag-default-function' is the right place to handle this in
a mode specific way.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Tiny change to find-tag-default.
2006-07-21 9:53 Tiny change to find-tag-default Kim F. Storm
2006-07-21 14:18 ` Drew Adams
2006-07-22 4:39 ` Richard Stallman
@ 2006-07-28 23:04 ` Kim F. Storm
2 siblings, 0 replies; 11+ messages in thread
From: Kim F. Storm @ 2006-07-28 23:04 UTC (permalink / raw)
I installed the functionality described below -- but only for to the grep commands.
So I didn't touch on find-tag-default.
storm@cua.dk (Kim F. Storm) writes:
> The following way of working seems natural to me -- but doesn't work.
> [I have transient-mark-mode == t]
>
>
> Suppose I'm looking at a text, and want to grep for a phrase
> (e.g. just two words) in that text, I highlight the text to search for
> (set mark, go to end of text) and do M-x lgrep.
>
> However, this ignores my selection, and just suggests the word at point
> at the regexp.
--
Kim F. Storm <storm@cua.dk> http://www.cua.dk
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Tiny change to find-tag-default.
2006-07-23 17:34 ` Richard Stallman
@ 2006-07-28 23:06 ` Kim F. Storm
0 siblings, 0 replies; 11+ messages in thread
From: Kim F. Storm @ 2006-07-28 23:06 UTC (permalink / raw)
Cc: martin rudalics, emacs-devel
Richard Stallman <rms@gnu.org> writes:
> Wouldn't it make sense to rewrite the rest of `find-tag-default' too?
> In its current version it unnecessarily clobbers `match-data', requires
> a `condition-case' to handle errors in `forward-sexp', and has other
> tedious things like repeated forward-charing and re-searching.
>
> That isn't a core part of the system, so I see no need to reject this.
I don't see any real benefit from "fixing" find-tag-default at this stage
(since it isn't broken).
IMO, we should leave it alone for now, and "fix" it after the release.
--
Kim F. Storm <storm@cua.dk> http://www.cua.dk
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2006-07-28 23:06 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-07-21 9:53 Tiny change to find-tag-default Kim F. Storm
2006-07-21 14:18 ` Drew Adams
2006-07-21 22:21 ` Kim F. Storm
2006-07-21 23:15 ` Drew Adams
2006-07-22 4:39 ` Richard Stallman
2006-07-22 12:17 ` martin rudalics
2006-07-23 17:34 ` Richard Stallman
2006-07-28 23:06 ` Kim F. Storm
2006-07-28 0:09 ` Kim F. Storm
2006-07-28 9:12 ` martin rudalics
2006-07-28 23:04 ` Kim F. Storm
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.