From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Wojciech Meyer Newsgroups: gmane.emacs.devel Subject: Re: How do I use tags to go to begv_byte instead of BEGV_BYTE? Date: Sun, 29 Aug 2010 02:04:59 +0100 Message-ID: <8762yup6tg.fsf@gmail.com> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: dough.gmane.org 1283043952 10812 80.91.229.12 (29 Aug 2010 01:05:52 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 29 Aug 2010 01:05:52 +0000 (UTC) Cc: Andreas Schwab , Lennart Borgman , Emacs-Devel devel To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Aug 29 03:05:49 2010 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1OpWLE-0002D9-Jy for ged-emacs-devel@m.gmane.org; Sun, 29 Aug 2010 03:05:48 +0200 Original-Received: from localhost ([127.0.0.1]:45101 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OpWLD-0007Df-Um for ged-emacs-devel@m.gmane.org; Sat, 28 Aug 2010 21:05:47 -0400 Original-Received: from [140.186.70.92] (port=45487 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OpWL6-0007CZ-I4 for emacs-devel@gnu.org; Sat, 28 Aug 2010 21:05:42 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OpWL4-0007KV-NJ for emacs-devel@gnu.org; Sat, 28 Aug 2010 21:05:40 -0400 Original-Received: from mail-ww0-f49.google.com ([74.125.82.49]:37386) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OpWL4-0007KO-Fw for emacs-devel@gnu.org; Sat, 28 Aug 2010 21:05:38 -0400 Original-Received: by wwb24 with SMTP id 24so1380301wwb.30 for ; Sat, 28 Aug 2010 18:05:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:references :date:in-reply-to:message-id:user-agent:mime-version:content-type; bh=8Os8tZ0YdHQqdnxeqJ+FUmFeC5aIG9PgNiW4c5b+reo=; b=ai+sQEU1DDjdjhzTNWafF8U/+zir5ub4S2Md0FAMKB/0zcV9z75LIXyHgXN7KvmBlh GL6hJo2m+jkIetUji7FYaObuGoIy6Epvr53W5mlyg2E2jtuoLLrxCPMmX4AxiJuZDOHa VYTtTmQucNOYPc74quPE2NYVEZArDGkpM/35Q= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type; b=LnatlmqwMZiiNZsYHEgzVthIkiIg1yz0gJmxwMX6b2kro/EZOcLpk+xu4CHhmX/4va w0ehyzyROqahpCBVJ3iYoBp3iH7srzF1bkS2ojERGE5gPSwNWKGgzXxAVy1yH2UJFJDt /Ipg8hVQNG8JTsXiCRdH5URENZFqCSySA9S8U= Original-Received: by 10.227.41.2 with SMTP id m2mr2638423wbe.12.1283043937419; Sat, 28 Aug 2010 18:05:37 -0700 (PDT) Original-Received: from spec-desktop.specuu.com (host86-134-71-68.range86-134.btcentralplus.com [86.134.71.68]) by mx.google.com with ESMTPS id w1sm3488421weq.1.2010.08.28.18.05.35 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sat, 28 Aug 2010 18:05:36 -0700 (PDT) In-Reply-To: (Stefan Monnier's message of "Mon, 24 May 2010 13:31:40 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:129373 Archived-At: --=-=-= Stefan Monnier writes: > Nowadays, I think etags.el would deserve to be improved so as to taken > the major mode into account, and also so as to give precedence to > case-exact matches, and also to automatically try the second-choice if > the first makes you jump to where you started. > > IOW patches welcome, Here is another one. `tags-major-mode-sensitive' customisation allows to specify if `etags' package should be sensitive on a major mode. If so, it looks only for files with the names matching entries of `auto-mode-alist' of the major mode. It does not hit performance that much, if it is a problem, making a simple assumption about last search would be sufficient (however I've checked it on the Emacs code base, and seems to run OK). BTW: Integrating etags with ede projects might be a good idea. Cheers; Wojciech --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=etags-major-mode-sensitive.patch === modified file 'lisp/progmodes/etags.el' --- lisp/progmodes/etags.el 2010-08-14 23:01:42 +0000 +++ lisp/progmodes/etags.el 2010-08-29 00:46:18 +0000 @@ -103,6 +103,15 @@ :group 'etags :type 'boolean) +(defcustom tags-major-mode-sensitive 'default + "*Control whether major mode determines allowed file extensions during +tags search." + :group 'etags + :type '(choice (const :tag "Major mode file types only" t) + (const :tag "All files " nil) + (other :tag "Use default" default)) + :version "21.1") + (defvar tags-table-computed-list nil "List of tags tables to search, computed from `tags-table-list'. This includes tables implicitly included by other tables. The list is not @@ -879,7 +888,8 @@ ;; Save the current buffer's value of `find-tag-hook' before ;; selecting the tags table buffer. For the same reason, save value ;; of `tags-file-name' in case it has a buffer-local value. - (let ((local-find-tag-hook find-tag-hook)) + (let ((local-find-tag-hook find-tag-hook) + (current-major-mode major-mode)) (if (eq '- next-p) ;; Pop back to a previous location. (if (ring-empty-p tags-location-ring) @@ -919,7 +929,7 @@ find-tag-regexp-next-line-after-failure-p find-tag-next-line-after-failure-p) (if regexp-p "matching" "containing") - (or (not next-p) (not last-tag))) + (or (not next-p) (not last-tag)) current-major-mode) (set-marker marker (point)) (run-hooks 'local-find-tag-hook) (ring-insert tags-location-ring marker) @@ -1061,6 +1071,26 @@ (goto-char (marker-position marker)) (set-marker marker nil nil))) + +(defun tags-file-name-qualified-p (file-name current-major-mode) + "Is file name qualified? Return always t if `tags-major-mode-sensitive' +is nil. Otherwise return if the file matches major-mode file name regexp." + (if (or + (null tags-major-mode-sensitive) + (eq tags-major-mode-sensitive 'default)) + t + (let ((al auto-mode-alist) + (found nil)) + (while (and (not found) al) + (let* ((x (car al)) + (file-name-regex (car x)) + (major-mode-sym (cdr x))) + (setq al (cdr al)) + (setq found (and + (eq current-major-mode major-mode-sym) + (string-match file-name-regex file-name))))) + found))) + (defvar tag-lines-already-matched nil "Matches remembered between calls.") ; Doc string: calls to what? @@ -1069,7 +1099,8 @@ order next-line-after-failure-p matching - first-search) + first-search + current-major-mode) "Internal tag-finding function. PATTERN is a string to pass to arg SEARCH-FORWARD-FUNC, and to any member of the function list ORDER. If ORDER is nil, use saved state @@ -1129,7 +1160,8 @@ (while order (while (funcall search-forward-func pattern nil t) ;; Naive match found. Qualify the match. - (and (funcall (car order) pattern) + (and (tags-file-name-qualified-p (file-of-tag) current-major-mode) + (funcall (car order) pattern) ;; Make sure it is not a previous qualified match. (not (member (set-marker match-marker (save-excursion (beginning-of-line) --=-=-=--