From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#14427: 24.3.50; Highlight symbol at point Date: Tue, 21 May 2013 22:07:49 +0300 Organization: JURTA Message-ID: <87r4h0jgmy.fsf@mail.jurta.org> References: <87ppwlb6tx.fsf@mail.jurta.org> <87ip2d9qp6.fsf@mail.jurta.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1369163730 28284 80.91.229.3 (21 May 2013 19:15:30 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 21 May 2013 19:15:30 +0000 (UTC) To: 14427@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue May 21 21:15:30 2013 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Ues1w-0007aE-OI for geb-bug-gnu-emacs@m.gmane.org; Tue, 21 May 2013 21:15:28 +0200 Original-Received: from localhost ([::1]:42646 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ues1w-0004nN-B3 for geb-bug-gnu-emacs@m.gmane.org; Tue, 21 May 2013 15:15:28 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:47147) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ues1s-0004nH-1s for bug-gnu-emacs@gnu.org; Tue, 21 May 2013 15:15:25 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ues1q-0001Cq-Ge for bug-gnu-emacs@gnu.org; Tue, 21 May 2013 15:15:24 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:38456) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ues1q-0001Ck-CG for bug-gnu-emacs@gnu.org; Tue, 21 May 2013 15:15:22 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1Ues2T-0006UQ-QX for bug-gnu-emacs@gnu.org; Tue, 21 May 2013 15:16:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 21 May 2013 19:16:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 14427 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 14427-submit@debbugs.gnu.org id=B14427.136916375824937 (code B ref 14427); Tue, 21 May 2013 19:16:01 +0000 Original-Received: (at 14427) by debbugs.gnu.org; 21 May 2013 19:15:58 +0000 Original-Received: from localhost ([127.0.0.1]:55047 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Ues2Q-0006UA-9x for submit@debbugs.gnu.org; Tue, 21 May 2013 15:15:58 -0400 Original-Received: from ps18281.dreamhost.com ([69.163.218.105]:49861 helo=ps18281.dreamhostps.com) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Ues2N-0006U0-0u for 14427@debbugs.gnu.org; Tue, 21 May 2013 15:15:56 -0400 Original-Received: from localhost (ps18281.dreamhostps.com [69.163.218.105]) by ps18281.dreamhostps.com (Postfix) with ESMTP id 4C653258B9E938 for <14427@debbugs.gnu.org>; Tue, 21 May 2013 12:15:12 -0700 (PDT) In-Reply-To: <87ip2d9qp6.fsf@mail.jurta.org> (Juri Linkov's message of "Tue, 21 May 2013 02:28:21 +0300") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (x86_64-pc-linux-gnu) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:74436 Archived-At: 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.