GNU bug report logs - #14427
24.3.50; Highlight symbol at point

Previous Next

Package: emacs;

Reported by: Juri Linkov <juri <at> jurta.org>

Date: Mon, 20 May 2013 23:04:01 UTC

Severity: wishlist

Tags: patch

Found in version 24.3.50

Done: Juri Linkov <juri <at> jurta.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 14427 in the body.
You can then email your comments to 14427 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#14427; Package emacs. (Mon, 20 May 2013 23:04:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Juri Linkov <juri <at> jurta.org>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 20 May 2013 23:04:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> jurta.org>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.3.50; Highlight symbol at point
Date: Tue, 21 May 2013 01:54:34 +0300
This feature request mostly doesn't depend on the outcome of bug#14405.
I don't know why Jambunathan didn't propose this feature earlier, but it
logically follows from his other improvements in hi-lock.el, i.e. the
feature that doesn't ask for a face and automatically uses the next face
from the list of available faces suggests also a command that doesn't ask
for a symbol and automatically uses the symbol at point:

=== modified file 'lisp/hi-lock.el'
--- lisp/hi-lock.el	2013-03-31 13:34:35 +0000
+++ lisp/hi-lock.el	2013-05-20 22:52:54 +0000
@@ -483,6 +461,27 @@ (defun hi-lock-face-phrase-buffer (regex
   (unless hi-lock-mode (hi-lock-mode 1))
   (hi-lock-set-pattern regexp face))
 
+;;;###autoload
+(defalias 'highlight-symbol-at-point 'hi-lock-face-symbol-at-point)
+;;;###autoload
+(defun hi-lock-face-symbol-at-point ()
+  "Set face of each match of the symbol at point.
+Use `find-tag-default-as-symbol-regexp' to retrieve the symbol at point.
+Use non-nil `hi-lock-auto-select-face' to retrieve the next face
+from `hi-lock-face-defaults' automatically.
+
+Use Font lock mode, if enabled, to highlight symbol at point.
+Otherwise, use overlays for highlighting.  If overlays are used,
+the highlighting will not update as you type."
+  (interactive)
+  (let* ((regexp (hi-lock-regexp-okay
+		  (find-tag-default-as-symbol-regexp)))
+	 (hi-lock-auto-select-face t)
+	 (face (hi-lock-read-face-name)))
+    (or (facep face) (setq face 'hi-yellow))
+    (unless hi-lock-mode (hi-lock-mode 1))
+    (hi-lock-set-pattern regexp face)))
+
 (defun hi-lock-keyword->face (keyword)
   (cadr (cadr (cadr keyword))))    ; Keyword looks like (REGEXP (0 'FACE) ...).
 




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#14427; Package emacs. (Mon, 20 May 2013 23:32:02 GMT) Full text and rfc822 format available.

Message #8 received at 14427 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> jurta.org>
To: 14427 <at> debbugs.gnu.org
Subject: Re: bug#14427: 24.3.50; Highlight symbol at point
Date: Tue, 21 May 2013 02:28:21 +0300
BTW, the current symbol is incorrectly highlighted when
`hi-lock-face-buffer' is called from isearch.  This should be
fixed by this patch:

=== modified file 'lisp/isearch.el'
--- lisp/isearch.el	2013-05-18 22:46:59 +0000
+++ lisp/isearch.el	2013-05-20 23:27:28 +0000
@@ -1773,7 +1791,10 @@ (defun isearch-highlight-regexp ()
     (isearch-done nil t)
     (isearch-clean-overlays))
   (require 'hi-lock nil t)
-  (let ((string (cond (isearch-regexp isearch-string)
+  (let ((string (cond ((functionp isearch-word)
+		       (funcall isearch-word isearch-string))
+		      (isearch-word (word-search-regexp isearch-string))
+		      (isearch-regexp isearch-string)
 		      ((if (and (eq isearch-case-fold-search t)
 				search-upper-case)
 			   (isearch-no-upper-case-p

It still can't correctly set `case-fold-search' for hi-lock, but
this can't be improved because hi-lock is based on font-lock
when font-lock is enabled in the buffer, and changing
`font-lock-keywords-case-fold-search' to the same value as
`isearch-case-fold-search' might break font-lock highlighting
for its other default keywords.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#14427; Package emacs. (Tue, 21 May 2013 19:16:01 GMT) Full text and rfc822 format available.

Message #11 received at 14427 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> jurta.org>
To: 14427 <at> debbugs.gnu.org
Subject: Re: bug#14427: 24.3.50; Highlight symbol at point
Date: Tue, 21 May 2013 22:07:49 +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)))))
+
 
 ;; 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.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#14427; Package emacs. (Sun, 02 Jun 2013 10:04:02 GMT) Full text and rfc822 format available.

Message #14 received at 14427 <at> debbugs.gnu.org (full text, mbox):

From: Jambunathan K <kjambunathan <at> gmail.com>
To: Juri Linkov <juri <at> jurta.org>
Cc: 14427 <at> debbugs.gnu.org
Subject: Re: bug#14427: 24.3.50; Highlight symbol at point
Date: Sun, 02 Jun 2013 15:31:48 +0530
If you could commit this change, I can start using it right away.  I
have no firm opinion on whether `hi-lock-auto-select-face' should come
from user setting or be let bound.

Remember to provide a keybinding in hi-lock mode.  I suggest C-x w
"dot".

Juri Linkov <juri <at> jurta.org> writes:

> This feature request mostly doesn't depend on the outcome of bug#14405.
> I don't know why Jambunathan didn't propose this feature earlier, but it
> logically follows from his other improvements in hi-lock.el, i.e. the
> feature that doesn't ask for a face and automatically uses the next face
> from the list of available faces suggests also a command that doesn't ask
> for a symbol and automatically uses the symbol at point:
>
> === modified file 'lisp/hi-lock.el'
> --- lisp/hi-lock.el	2013-03-31 13:34:35 +0000
> +++ lisp/hi-lock.el	2013-05-20 22:52:54 +0000
> @@ -483,6 +461,27 @@ (defun hi-lock-face-phrase-buffer (regex
>    (unless hi-lock-mode (hi-lock-mode 1))
>    (hi-lock-set-pattern regexp face))
>  
> +;;;###autoload
> +(defalias 'highlight-symbol-at-point 'hi-lock-face-symbol-at-point)
> +;;;###autoload
> +(defun hi-lock-face-symbol-at-point ()
> +  "Set face of each match of the symbol at point.
> +Use `find-tag-default-as-symbol-regexp' to retrieve the symbol at point.
> +Use non-nil `hi-lock-auto-select-face' to retrieve the next face
> +from `hi-lock-face-defaults' automatically.
> +
> +Use Font lock mode, if enabled, to highlight symbol at point.
> +Otherwise, use overlays for highlighting.  If overlays are used,
> +the highlighting will not update as you type."
> +  (interactive)
> +  (let* ((regexp (hi-lock-regexp-okay
> +		  (find-tag-default-as-symbol-regexp)))
> +	 (hi-lock-auto-select-face t)
> +	 (face (hi-lock-read-face-name)))
> +    (or (facep face) (setq face 'hi-yellow))
> +    (unless hi-lock-mode (hi-lock-mode 1))
> +    (hi-lock-set-pattern regexp face)))
> +
>  (defun hi-lock-keyword->face (keyword)
>    (cadr (cadr (cadr keyword))))    ; Keyword looks like (REGEXP (0 'FACE) ...).
>  




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#14427; Package emacs. (Sun, 02 Jun 2013 10:07:01 GMT) Full text and rfc822 format available.

Message #17 received at 14427 <at> debbugs.gnu.org (full text, mbox):

From: Jambunathan K <kjambunathan <at> gmail.com>
To: Juri Linkov <juri <at> jurta.org>
Cc: 14427 <at> debbugs.gnu.org
Subject: Re: bug#14427: 24.3.50; Highlight symbol at point
Date: Sun, 02 Jun 2013 15:34:28 +0530
Jambunathan K <kjambunathan <at> gmail.com> writes:

> If you could commit this change, I can start using it right away.

Small note.  I haven't tested the isearch portions of the patch.




Reply sent to Juri Linkov <juri <at> jurta.org>:
You have taken responsibility. (Mon, 03 Jun 2013 08:58:02 GMT) Full text and rfc822 format available.

Notification sent to Juri Linkov <juri <at> jurta.org>:
bug acknowledged by developer. (Mon, 03 Jun 2013 08:58:02 GMT) Full text and rfc822 format available.

Message #22 received at 14427-done <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> jurta.org>
To: Jambunathan K <kjambunathan <at> gmail.com>
Cc: 14427-done <at> debbugs.gnu.org
Subject: Re: bug#14427: 24.3.50; Highlight symbol at point
Date: Mon, 03 Jun 2013 11:54:05 +0300
>> If you could commit this change, I can start using it right away.

Thanks for the reminder, this is installed now.

> Small note.  I haven't tested the isearch portions of the patch.

Isearch integration with hi-lock is far from ideal yet.
The limiting factor is that hi-lock is based on font-lock
when font-lock is enabled.  Otherwise, it is plain search-based.

Perhaps we should check in `isearch-highlight-regexp'
whether font-lock is active in the current buffer,
and when font-lock is disabled then let-bind all relevant
search variables like `lax-whitespace', `search-invisible',
filters, etc.  So search-based hi-lock will be able to highlight
correctly the same matches as isearch.

This will provide the correct conversion of the search parameters
to hi-lock (at least partly for the case when font-lock is disabled
and hi-lock is search-based).




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 01 Jul 2013 11:24:02 GMT) Full text and rfc822 format available.

This bug report was last modified 10 years and 327 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.