From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: martin rudalics Newsgroups: gmane.emacs.devel Subject: Re: patch: add-log.el: changelog find file under poin Date: Mon, 28 Jan 2008 11:20:05 +0100 Message-ID: <479DAC55.8070302@gmx.at> References: <1194211092.13041.13.camel@peder.flower> <200801222310.m0MN9cZq011601@sallyv1.ics.uci.edu> <8763xl492o.fsf@jurta.org> <200801230225.m0N2Ptmx012952@sallyv1.ics.uci.edu> <200801271954.m0RJsmBm003714@sallyv1.ics.uci.edu> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------030800040706020603070600" X-Trace: ger.gmane.org 1201515636 22178 80.91.229.12 (28 Jan 2008 10:20:36 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 28 Jan 2008 10:20:36 +0000 (UTC) Cc: juri@jurta.org, rgm@gnu.org, emacs-devel@gnu.org, rms@gnu.org, janneke-list@xs4all.nl To: Dan Nicolaescu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Jan 28 11:20:55 2008 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.50) id 1JJR6b-0006Yx-5W for ged-emacs-devel@m.gmane.org; Mon, 28 Jan 2008 11:20:45 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JJR69-0005pQ-NU for ged-emacs-devel@m.gmane.org; Mon, 28 Jan 2008 05:20:17 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JJR62-0005o0-RM for emacs-devel@gnu.org; Mon, 28 Jan 2008 05:20:10 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JJR60-0005na-Rt for emacs-devel@gnu.org; Mon, 28 Jan 2008 05:20:09 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JJR60-0005nX-Gm for emacs-devel@gnu.org; Mon, 28 Jan 2008 05:20:08 -0500 Original-Received: from mail.gmx.net ([213.165.64.20]) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1JJR5z-0006ZM-Lo for emacs-devel@gnu.org; Mon, 28 Jan 2008 05:20:08 -0500 Original-Received: (qmail invoked by alias); 28 Jan 2008 10:20:06 -0000 Original-Received: from N815P006.adsl.highway.telekom.at (EHLO [62.47.45.198]) [62.47.45.198] by mail.gmx.net (mp055) with SMTP; 28 Jan 2008 11:20:06 +0100 X-Authenticated: #14592706 X-Provags-ID: V01U2FsdGVkX18Mfo4SrSgMOlrr4/Ep2FPvaqbVt1hfwXzujWL+8n jv51oqoMS9NJhc User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: de-DE, de, en-us, en In-Reply-To: <200801271954.m0RJsmBm003714@sallyv1.ics.uci.edu> X-Y-GMX-Trusted: 0 X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 1) 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:87703 Archived-At: This is a multi-part message in MIME format. --------------030800040706020603070600 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit > Based on that I checked this original patch in (Thanks Jan!). > And I made it a bit more robust in finding the correct file name. > If someone can figure out a way to use ffap that is at least as > reliable, then we can replace the current code. Based on what you wrote and Imenu I added support to find the "tag" within the file with C-c C-t. Rudimentary and largely untested! If anyone is interested I can refine that though. --------------030800040706020603070600 Content-Type: text/plain; name="add-log.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="add-log.patch" *** add-log.el Sun Jan 27 22:30:56 2008 --- add-log.el Mon Jan 28 11:16:12 2008 *************** *** 328,338 **** --- 328,456 ---- (find-file file) (message "No such file or directory: %s" file)))) + (defconst change-log-tag-re "(\\(\\(?:\\sw\\|\\s_\\)+\\(?:,[ \t]+\\(?:\\sw\\|\\s_\\)+\\)*\\))") + + (defun change-log-search-tag (&optional at) + "Search for something qualifying as tag." + (save-excursion + (goto-char (setq at (or at (point)))) + (save-restriction + (widen) + (or (condition-case nil + ;; Test for AT within list containing tags. + (save-excursion + (backward-up-list) + (when (looking-at change-log-tag-re) + (goto-char at) + (save-restriction + (narrow-to-region (match-beginning 1) (match-end 1)) + (find-tag-default)))) + (error nil)) + (condition-case nil + ;; Test for AT before list containing tags. + (save-excursion + (when (and (skip-chars-forward " \t") ; syntax goes to far + (looking-at change-log-tag-re)) + (save-restriction + (narrow-to-region (match-beginning 1) (match-end 1)) + (goto-char (point-min)) + (find-tag-default)))) + (error nil)) + (condition-case nil + ;; Test for AT near filename. + (save-excursion + (when (and (progn + (beginning-of-line) + (looking-at change-log-file-names-re)) + (goto-char (match-end 0)) + (skip-syntax-forward " ") + (looking-at change-log-tag-re)) + (save-restriction + (narrow-to-region (match-beginning 1) (match-end 1)) + (goto-char (point-min)) + (find-tag-default)))) + (error nil)) + (condition-case nil + ;; Test for AT before filename. + (save-excursion + (when (and (progn + (skip-syntax-backward " ") + (beginning-of-line) + (looking-at change-log-file-names-re)) + (goto-char (match-end 0)) + (skip-syntax-forward " ") + (looking-at change-log-tag-re)) + (save-restriction + (narrow-to-region (match-beginning 1) (match-end 1)) + (goto-char (point-min)) + (find-tag-default)))) + (error nil)) + (condition-case nil + ;; Test for AT near start entry. + (save-excursion + (when (and (progn + (beginning-of-line) + (looking-at change-log-start-entry-re)) + (forward-line) ; Won't work for multiple + ; names, etc. + (skip-syntax-forward " ") + (progn + (beginning-of-line) + (looking-at change-log-file-names-re)) + (goto-char (match-end 0)) + (re-search-forward change-log-tag-re)) + (save-restriction + (narrow-to-region (match-beginning 1) (match-end 1)) + (goto-char (point-min)) + (find-tag-default)))) + (error nil)) + (condition-case nil + ;; Test for AT after tag list. + (when (re-search-backward change-log-tag-re) + (save-restriction + (narrow-to-region (match-beginning 1) (match-end 1)) + (goto-char (point-max)) + (find-tag-default))) + (error nil)))))) + + (defun change-log-find-tag () + "Find tag using Imenu." + (interactive) + (let ((file (change-log-search-file-name (point))) + (tag (change-log-search-tag (point)))) + (cond + ((and tag file (file-exists-p file)) + (let ((buffer (find-file-noselect file)) + position) + (if buffer + (with-current-buffer buffer + (require 'imenu) + (save-excursion + (save-restriction + (widen) + (condition-case nil + (let* (imenu-use-markers element ; don't use markers. + (tags (funcall imenu-create-index-function))) + ;; TODO: Handle case of more than one + ;; association for tag. + (if (setq element (assoc tag tags)) + (setq position (cdr element)) + (message "Not found tag: %s" tag))) + (error nil)))) + (when position + (goto-char position) + (display-buffer buffer))) + (message "Cannot find file: %s" file)))) + ((not tag) (message "No such tag: %s" tag)) + (t (message "No such file or directory: %s" file))))) + + (defvar change-log-mode-map (let ((map (make-sparse-keymap))) (define-key map [?\C-c ?\C-p] 'add-log-edit-prev-comment) (define-key map [?\C-c ?\C-n] 'add-log-edit-next-comment) (define-key map [?\C-c ?\C-f] 'change-log-find-file) + (define-key map [?\C-c ?\C-t] 'change-log-find-tag) map) "Keymap for Change Log major mode.") *************** *** 938,944 **** having-next-defun previous-defun-end next-defun-beginning) ! (save-excursion (setq having-previous-defun (c-beginning-of-defun)) --- 1056,1062 ---- having-next-defun previous-defun-end next-defun-beginning) ! (save-excursion (setq having-previous-defun (c-beginning-of-defun)) --------------030800040706020603070600 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel --------------030800040706020603070600--