unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* header files in woman.el
@ 2003-03-30 11:45 Masatake YAMATO
  2003-03-31  8:37 ` Richard Stallman
  0 siblings, 1 reply; 9+ messages in thread
From: Masatake YAMATO @ 2003-03-30 11:45 UTC (permalink / raw)
  Cc: emacs-devel

Hi,

I've added buttons for header files(e.g. #include <foo.h>) 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)
+
 \f
 ;; 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.")
+
 \f
 ;;; 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")
+
 \f
 ;;; 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 <foo.h>) 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)))
 
 \f
 ;;; Buffer handling:
@@ -4548,4 +4622,18 @@
 
 (provide 'woman)
 
+\f
+;; 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

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2003-04-02  9:19 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-03-30 11:45 header files in woman.el Masatake YAMATO
2003-03-31  8:37 ` Richard Stallman
2003-03-31 15:43   ` Masatake YAMATO
2003-03-31 16:35     ` Dr Francis J. Wright
2003-04-01  9:38       ` Richard Stallman
2003-04-01 10:03         ` Dr Francis J. Wright
2003-04-01  9:37     ` Richard Stallman
2003-04-01  9:44       ` Masatake YAMATO
2003-04-02  9:19         ` Richard Stallman

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).