unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@jurta.org>
To: 14427@debbugs.gnu.org
Subject: bug#14427: 24.3.50; Highlight symbol at point
Date: Tue, 21 May 2013 22:07:49 +0300	[thread overview]
Message-ID: <87r4h0jgmy.fsf@mail.jurta.org> (raw)
In-Reply-To: <87ip2d9qp6.fsf@mail.jurta.org> (Juri Linkov's message of "Tue, 21 May 2013 02:28:21 +0300")

The intention was to accompany the proposed `highlight-symbol-at-point'
with its isearch correlate.  This feature was requested long ago in
http://www.emacswiki.org/emacs/SearchAtPoint
and after recent improvements it is straightforward to implement now.

For keybindings it makes sense to take the command `find-tag'
as a model with its keybinding `M-.' since `find-tag' searches
for a tag in source code and `isearch-forward-symbol-at-point' and
`highlight-symbol-at-point' should do the same only in the current buffer:

M-.     - find-tag
M-s .   - isearch-forward-symbol-at-point
M-s h . - highlight-symbol-at-point

=== modified file 'lisp/bindings.el'
--- lisp/bindings.el	2013-04-22 04:17:30 +0000
+++ lisp/bindings.el	2013-05-21 19:05:45 +0000
@@ -892,6 +892,7 @@ (define-key esc-map "s" search-map)
 
 (define-key search-map "o"  'occur)
 (define-key search-map "hr" 'highlight-regexp)
+(define-key search-map "h." 'highlight-symbol-at-point)
 (define-key search-map "hp" 'highlight-phrase)
 (define-key search-map "hl" 'highlight-lines-matching-regexp)
 (define-key search-map "hu" 'unhighlight-regexp)

=== modified file 'lisp/isearch.el'
--- lisp/isearch.el	2013-05-18 22:46:59 +0000
+++ lisp/isearch.el	2013-05-21 18:59:23 +0000
@@ -677,6 +677,7 @@ (define-key global-map "\C-r" 'isearch-b
 (define-key esc-map "\C-r" 'isearch-backward-regexp)
 (define-key search-map "w" 'isearch-forward-word)
 (define-key search-map "_" 'isearch-forward-symbol)
+(define-key search-map "." 'isearch-forward-symbol-at-point)
 
 ;; Entry points to isearch-mode.
 
@@ -817,6 +818,25 @@ (defun isearch-backward-regexp (&optiona
   (interactive "P\np")
   (isearch-mode nil (null not-regexp) nil (not no-recursive-edit)))
 
+(defun isearch-forward-symbol-at-point ()
+  "Do incremental search forward for a symbol found near point.
+Like ordinary incremental search except that the symbol found at point
+is added to the search string initially as a regexp surrounded
+by symbol boundary constructs \\_< and \\_>.
+See the command `isearch-forward-symbol' for more information."
+  (interactive)
+  (isearch-forward-symbol nil 1)
+  (let ((bounds (find-tag-default-bounds)))
+    (cond
+     (bounds
+      (when (< (car bounds) (point))
+	(goto-char (car bounds)))
+      (isearch-yank-string
+       (buffer-substring-no-properties (car bounds) (cdr bounds))))
+     (t
+      (setq isearch-error "No symbol at point")
+      (isearch-update)))))
+
 \f
 ;; isearch-mode only sets up incremental search for the minor mode.
 ;; All the work is done by the isearch-mode commands.


PS: One problem was that `find-tag-default' returns only a tag as a string,
not its exact location, but it's necessary to move point to the beginning
of the symbol.  To solve this problem, another patch splits `find-tag-default'
with part of code moved to `find-tag-default-bounds' that returns
the beginning anf end of the found tag:

=== modified file 'lisp/subr.el'
--- lisp/subr.el	2013-05-18 22:46:59 +0000
+++ lisp/subr.el	2013-05-21 19:07:07 +0000
@@ -2717,9 +2717,7 @@ (defsubst buffer-narrowed-p ()
   "Return non-nil if the current buffer is narrowed."
   (/= (- (point-max) (point-min)) (buffer-size)))
 
-(defun find-tag-default ()
-  "Determine default tag to search for, based on text at point.
-If there is no plausible default, return nil."
+(defun find-tag-default-bounds ()
   (let (from to bound)
     (when (or (progn
 		;; Look at text around `point'.
@@ -2742,7 +2740,14 @@ (defun find-tag-default ()
 		     (< (setq from (point)) bound)
 		     (skip-syntax-forward "w_")
 		     (setq to (point)))))
-      (buffer-substring-no-properties from to))))
+      (cons from to))))
+
+(defun find-tag-default ()
+  "Determine default tag to search for, based on text at point.
+If there is no plausible default, return nil."
+  (let ((bounds (find-tag-default-bounds)))
+    (when bounds
+      (buffer-substring-no-properties (car bounds) (cdr bounds)))))
 
 (defun find-tag-default-as-regexp ()
   "Return regexp that matches the default tag at point.






  reply	other threads:[~2013-05-21 19:07 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-20 22:54 bug#14427: 24.3.50; Highlight symbol at point Juri Linkov
2013-05-20 23:28 ` Juri Linkov
2013-05-21 19:07   ` Juri Linkov [this message]
2013-06-02 10:01 ` Jambunathan K
2013-06-02 10:04   ` Jambunathan K
2013-06-03  8:54     ` Juri Linkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r4h0jgmy.fsf@mail.jurta.org \
    --to=juri@jurta.org \
    --cc=14427@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).