From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Masatake YAMATO Newsgroups: gmane.emacs.devel Subject: header files in woman.el Date: Sun, 30 Mar 2003 20:45:54 +0900 (JST) Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <20030330.204554.59471538.jet@gyve.org> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: main.gmane.org 1049026864 22830 80.91.224.249 (30 Mar 2003 12:21:04 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Sun, 30 Mar 2003 12:21:04 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Sun Mar 30 14:21:03 2003 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 18zbnk-0005vG-00 for ; Sun, 30 Mar 2003 14:20:40 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 18zbr4-0006pU-00 for ; Sun, 30 Mar 2003 14:24:06 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18zblx-0006tA-04 for emacs-devel@quimby.gnus.org; Sun, 30 Mar 2003 07:18:49 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10.13) id 18zblH-0006Rm-00 for emacs-devel@gnu.org; Sun, 30 Mar 2003 07:18:07 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10.13) id 18zbl5-0005yb-00 for emacs-devel@gnu.org; Sun, 30 Mar 2003 07:17:59 -0500 Original-Received: from r-maa.spacetown.ne.jp ([210.130.136.40]) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18zbkz-0005dW-00 for emacs-devel@gnu.org; Sun, 30 Mar 2003 07:17:49 -0500 Original-Received: from localhost (h219-110-074-034.catv01.itscom.jp [219.110.74.34]) by r-maa.spacetown.ne.jp (8.11.6) with ESMTP id h2UCHdC07627; Sun, 30 Mar 2003 21:17:41 +0900 (JST) Original-To: F.J.Wright@qmul.ac.uk X-Mailer: Mew version 3.1.52 on Emacs 21.3 / Mule 5.0 (SAKAKI) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Emacs development discussions. List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:12749 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:12749 Hi, I've added buttons for header files(e.g. #include ) and files in FILES section to woman.el. So a user can jump to the files with mouse-2 or return key. Could you approve this function? I'm using woman.el in CVS version of GNU Emacs. (defvar woman-version "0.551 (beta)" "WoMan version information.") Masatake YAMATO Index: lisp/woman.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/woman.el,v retrieving revision 1.15 diff -u -r1.15 woman.el --- lisp/woman.el 31 Jan 2003 15:18:38 -0000 1.15 +++ lisp/woman.el 30 Mar 2003 11:51:14 -0000 @@ -792,6 +792,24 @@ :type 'boolean :group 'woman-interface) +(defcustom woman-synopsis-regexp "SYNOPSIS" + "Regular expression for SYNOPSIS heading (or your equivalent). +This regexp should not start with a `^' character." + :type 'regexp + :group 'woman-interface) + +(defcustom woman-files-regexp "FILES" + "Regular expression for FILES heading (or your equivalent). +This regexp should not start with a `^' character." + :type 'regexp + :group 'woman-interface) + +(defcustom woman-header-file-path + '("/usr/include" "/usr/local/include") + "C Header file search path used in WoMan." + :type '(repeat string) + :group 'woman-interface) + ;; Formatting options @@ -1058,13 +1076,51 @@ Should include ?e, ?o (page even/odd) and either ?n (nroff) or ?t (troff). Default is '(?n ?e ?o). Set via `woman-emulation'.") +(defvar woman-include-regexp "#[ \t]*include[ \t]*" + "Regular expression describing the #include (directive of cpp).") + +(defvar woman-file-name-regexp "[^<>\" \t\n]+" + "Regular expression describing <> in #include line (directive of cpp).") + +(defvar woman-normal-file-prefix-regexp "[/~$]" + "Regular expression describing a file path appeared in FILES section.") + +(defvar woman-header-regexp + (concat "\\(" woman-include-regexp "\\)" + "[<\"]" + "\\(" woman-file-name-regexp "\\)" + "[>\"]") + "Regular expression describing references to header files.") + +(defvar woman-normal-file-regexp + (concat woman-normal-file-prefix-regexp woman-file-name-regexp) + "Regular expression describing references to normal files.") + ;;; Button types: -(define-button-type 'woman-xref +(define-button-type 'woman-xref-man-page 'action (lambda (button) (woman (button-label button))) 'help-echo "RET, mouse-2: display this man page") + +(define-button-type 'woman-xref-header-file + 'action (lambda (button) + (unless (woman-view-header-file (button-get button 'woman-target-string)) + (error "Cannot find header file: %s" w))) + 'help-echo "mouse-2: display this header file") + +(define-button-type 'woman-xref-normal-file + 'action (lambda (button) + (let ((f (substitute-in-file-name + (button-get button 'woman-target-string)))) + (if (file-exists-p f) + (if (file-readable-p f) + (view-file f) + (error "Cannot read a file: %s" f)) + (error "Cannot find a file: %s" f)))) + 'help-echo "mouse-2: mouse-2: display this file") + ;;; Specialized utility functions: @@ -1964,20 +2020,38 @@ (- (cadr time) (cadr WoMan-Man-start-time))))) (message "Man formatting done in %d seconds" time))) -(defun WoMan-highlight-references () - "Highlight the references (in the SEE ALSO section) on mouse-over." +(defun WoMan-highlight-references0 (start-section regexp button-pos target-pos type) ;; Based on `Man-build-references-alist' in `man'. - (when (Man-find-section Man-see-also-regexp) + (when (Man-find-section start-section) (forward-line 1) (let ((end (save-excursion - (Man-next-section 1) - (point)))) + (Man-next-section 1) + (point)))) (back-to-indentation) - (while (re-search-forward Man-reference-regexp end t) + (while (re-search-forward regexp end t) ;; Highlight reference when mouse is over it. ;; (NB: WoMan does not hyphenate!) - (make-text-button (match-beginning 1) (match-end 1) - 'type 'woman-xref))))) + (make-text-button + (match-beginning button-pos) + (match-end button-pos) + 'type type + 'woman-target-string (match-string target-pos) + ))))) + +(defun WoMan-highlight-references () + "Highlight the references on mouse-over. +references include items in the SEE ALSO section, +header file(#include ) and files in FILES" + (let ((just-dummy 0)) + (WoMan-highlight-references0 + Man-see-also-regexp Man-reference-regexp 1 just-dummy + 'woman-xref-man-page) + (WoMan-highlight-references0 + woman-synopsis-regexp woman-header-regexp 0 2 + 'woman-xref-header-file) + (WoMan-highlight-references0 + woman-files-regexp woman-normal-file-regexp 0 0 + 'woman-xref-normal-file))) ;;; Buffer handling: @@ -4548,4 +4622,18 @@ (provide 'woman) + +;; Header file support +(defun woman-view-header-file (file) + "View a header file specified by FILE from `woman-header-file-path'." + (let ((path woman-header-file-path) + complete-path) + (while path + (setq complete-path (concat (car path) "/" file) + path (cdr path)) + (if (file-readable-p complete-path) + (progn (view-file complete-path) + (setq path nil)) + (setq complete-path nil))) + complete-path)) ;;; woman.el ends here