From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: drkm Newsgroups: gmane.emacs.devel Subject: Re: defface location in describe-face Date: Tue, 4 Jan 2005 03:06:43 +0100 (CET) Message-ID: <20050104020643.92136.qmail@web25808.mail.ukl.yahoo.com> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: sea.gmane.org 1104804522 24117 80.91.229.6 (4 Jan 2005 02:08:42 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 4 Jan 2005 02:08:42 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jan 04 03:08:31 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1Cle7b-000116-00 for ; Tue, 04 Jan 2005 03:08:31 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CleIk-0002Tq-SU for ged-emacs-devel@m.gmane.org; Mon, 03 Jan 2005 21:20:03 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1CleIS-0002Rs-Ef for emacs-devel@gnu.org; Mon, 03 Jan 2005 21:19:44 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1CleIQ-0002RH-F1 for emacs-devel@gnu.org; Mon, 03 Jan 2005 21:19:43 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CleIQ-0002Qt-0v for emacs-devel@gnu.org; Mon, 03 Jan 2005 21:19:42 -0500 Original-Received: from [217.12.10.193] (helo=web25808.mail.ukl.yahoo.com) by monty-python.gnu.org with smtp (Exim 4.34) id 1Cle5s-0004OG-8z for emacs-devel@gnu.org; Mon, 03 Jan 2005 21:06:44 -0500 Original-Received: (qmail 92138 invoked by uid 60001); 4 Jan 2005 02:06:43 -0000 Original-Received: from [81.242.250.202] by web25808.mail.ukl.yahoo.com via HTTP; Tue, 04 Jan 2005 03:06:43 CET Original-To: emacs-devel@gnu.org 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: main.gmane.org gmane.emacs.devel:31781 [ It seems that Gmane have problem at this time. So I post with my web mail interface. I'm sorry if this email was posted twice, and for broken Reference:. ] Stefan Monnier writes: >> Why `describe-face' does not show a "Defined in `_file_'." button ? > Oversight. `defface' doesn't record the definition in load-history. > Patches welcome. I tried to follow the same way `describe-variable' do this, and adapt it to `describe-face'. The difficult point is that `find-func' library doesn't handle symbols but functions and variables. So I defined there a new variable, `find-face-regexp', and a new function, `find-face-noselect'. `find-face-noselect' is a copy of `find-variable-noselect', with: (let ((library (or file (symbol-file variable 'defvar)))) (find-function-search-for-symbol variable 'variable library))) replaced by (locally binding `find-variable-regexp'): (let ((library (or file (symbol-file face 'defface))) (find-variable-regexp find-face-regexp)) (find-function-search-for-symbol face 'variable library))) But I think `find-func' library should be fixed to handle arbitrary kind of symbol (or at least other standard things than functions and variables). Follow the patches, generated individualy by "diff -c". It's important to point out that I didn't test it so much, because I can't install a more recent CVS version than : (emacs-version) ==> "GNU Emacs 21.3.50.1 (i386-mingw-windows98.3000) of 2004-12-23 on FARIBA" To resume the changes: - cus-face.el: `custom-declare-face' adds face to `current-load-list' - faces.el: `describe-face' adds the string "Defined in ...", with the ad-hoc button to go to the face definition - help-mode.el: define the button type `help-face-def' - emacs-lisp/find-func.el: new variable `find-face-regexp', new function `find-face-noselect', and a minor docstring fix in `find-variable-noselect' --drkm *** cus-face.el.orig Thu Dec 23 07:01:56 2004 --- cus-face.el Tue Jan 4 01:25:46 2005 *************** *** 53,58 **** --- 53,59 ---- (when (and doc (null (face-documentation face))) (set-face-documentation face (purecopy doc))) (custom-handle-all-keywords face args 'custom-face) + (push (cons 'defface face) current-load-list) (run-hooks 'custom-define-hook)) face) *** faces.el.orig Thu Dec 23 07:01:58 2004 --- faces.el Tue Jan 4 02:38:50 2005 *************** *** 1244,1255 **** (insert "Documentation: " (or (face-documentation f) "Not documented as a face.") ! "\n\n") (with-current-buffer standard-output (save-excursion (re-search-backward (concat "\\(" customize-label "\\)") nil t) ! (help-xref-button 1 'help-customize-face f))) (dolist (a attrs) (let ((attr (face-attribute f (car a) frame))) (insert (make-string (- max-width (length (cdr a))) ?\ ) --- 1244,1279 ---- (insert "Documentation: " (or (face-documentation f) "Not documented as a face.") ! "\n") (with-current-buffer standard-output (save-excursion (re-search-backward (concat "\\(" customize-label "\\)") nil t) ! (help-xref-button 1 'help-customize-face f)) ! ;; Make a hyperlink to the library if appropriate. ! (let ((file-name (symbol-file (cons 'defface f)))) ! (when (equal file-name "loaddefs.el") ! ;; Find the real def site of the preloaded face. ! (let ((location ! (condition-case nil ! (find-face-noselect f file-name) ! (error nil)))) ! (when location ! (with-current-buffer (car location) ! (goto-char (cdr location)) ! (when (re-search-backward ! "^;;; Generated autoloads from \\(.*\\)" nil t) ! (setq file-name (match-string 1))))))) ! (when file-name ! (princ "Defined in `") ! (princ file-name) ! (princ "'.\n") ! (with-current-buffer standard-output ! (save-excursion ! (re-search-backward "`\\([^`']+\\)'" nil t) ! (help-xref-button 1 'help-face-def ! f file-name)))) ! (trepri))) (dolist (a attrs) (let ((attr (face-attribute f (car a) frame))) (insert (make-string (- max-width (length (cdr a))) ?\ ) *** help-mode.el.orig Thu Dec 23 07:01:58 2004 --- help-mode.el Tue Jan 4 02:16:48 2005 *************** *** 169,174 **** --- 169,182 ---- (goto-char (cdr location)))) 'help-echo (purecopy"mouse-2, RET: find variable's definition")) + (define-button-type 'help-face-def + :supertype 'help-xref + 'help-function (lambda (face &optional file) + (let ((location (find-face-noselect face file))) + (pop-to-buffer (car location)) + (goto-char (cdr location)))) + 'help-echo (purecopy "mouse-2, RET: find face's definition")) + ;;;###autoload (defun help-mode () *** emacs-lisp/find-func.el.orig Tue Jan 4 02:31:44 2005 --- emacs-lisp/find-func.el Tue Jan 4 02:14:22 2005 *************** *** 86,91 **** --- 86,102 ---- :group 'find-function :version "21.1") + (defcustom find-face-regexp + (concat"^\\s-*(defface" find-function-space-re "%s\\(\\s-\\|$\\)") + "The regexp used by `find-face' to search for a face definition. + It should match right up to the face name. The default value + matches `defface'. + + Please send improvements and fixes to the maintainer." + :type 'regexp + :group 'find-function + :version "21.3") + (defcustom find-function-source-path nil "The default list of directories where `find-function' searches. *************** *** 337,345 **** ;;;###autoload (defun find-variable-noselect (variable &optional file) ! "Return a pair `(BUFFER . POINT)' pointing to the definition of SYMBOL. ! Finds the Emacs Lisp library containing the definition of SYMBOL in a buffer and the point of the definition. The buffer is not selected. --- 348,356 ---- ;;;###autoload (defun find-variable-noselect (variable &optional file) ! "Return a pair `(BUFFER . POINT)' pointing to the definition of VARIABLE. ! Finds the Emacs Lisp library containing the definition of VARIABLE in a buffer and the point of the definition. The buffer is not selected. *************** *** 382,387 **** --- 393,414 ---- (find-function-do-it variable t 'switch-to-buffer-other-frame)) ;;;###autoload + (defun find-face-noselect (face &optional file) + "Return a pair `(BUFFER . POINT)' pointing to the definition of FACE. + + Finds the Emacs Lisp library containing the definition of FACE + in a buffer and the point of the definition. The buffer is + not selected. + + The library where FACE is defined is searched for in FILE or + `find-function-source-path', if non nil, otherwise in `load-path'." + (if (not face) + (error "You didn't specify a face")) + (let ((library (or file (symbol-file face 'defface))) + (find-variable-regexp find-face-regexp)) + (find-function-search-for-symbol face 'variable library))) + + ;;;###autoload (defun find-function-on-key (key) "Find the function that KEY invokes. KEY is a string. Point is saved if FUNCTION is in the current buffer." Découvrez le nouveau Yahoo! Mail : 250 Mo d'espace de stockage pour vos mails ! Créez votre Yahoo! Mail sur http://fr.mail.yahoo.com/