all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Masatake YAMATO <jet@gyve.org>
Cc: emacs-devel@gnu.org
Subject: Re: header files in woman.el
Date: Tue, 01 Apr 2003 00:43:18 +0900 (JST)	[thread overview]
Message-ID: <20030401.004318.75810358.jet@gyve.org> (raw)
In-Reply-To: <E18zun2-0002Nc-00@fencepost.gnu.org>

    woman.el uses Man mode in the buffer, once it has set up the buffer
    contents.  So I think the right place to implement this feature
    is in man.el.  If you implement this feature in man.el, it will
    work for woman.el too; it will work on all platforms.  But if you
    implement it in woman.el, it will not work in systems that use the
    man program.

    Could you reimplememt this inside of Man-follow?

I've tried. I've moved all woman.el's BUTTON related code to man.el; 
and I've used man.el's code in woman.el.

Masatake YAMATO

2003-04-01  Masatake YAMATO  <jet@gyve.org>

	* woman.el (woman-xref): removed.
	(woman-mode): Use `Man-highlight-references' instead of 
	`WoMan-highlight-references'.
	(WoMan-highlight-references): removed.

	* man.el (toplevel): require button.
	(Man-header-file-path): New option.
	(Man-synopsis-regexp, Man-files-regexp, Man-include-regexp)
	(Man-file-name-regexp, Man-normal-file-prefix-regexp)
	(Man-header-regexp, Man-normal-file-regexp): New variables.
	(Man-mode-map): inherited from `button-buffer-map'.
	(Man-mode-map): don't define "\r" and mouse-2 directly. 
	These key are defined in `button-buffer-map'.
	(Man-xref-man-page, Man-xref-header-file, Man-xref-normal-file): New buttons.
	`Man-xref-man-page' comes from woman.el.
	(man-follow-mouse): removed.
	(Man-fontify-manpage): use `Man-highlight-references' instead of calling
	`add-text-properties' directly.
	(Man-highlight-references, Man-highlight-references0): New functions.
	(Man-view-header-file): New function.

Index: woman.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/woman.el,v
retrieving revision 1.15
diff -u -r1.15 woman.el
--- woman.el	31 Jan 2003 15:18:38 -0000	1.15
+++ woman.el	31 Mar 2003 15:50:29 -0000
@@ -1059,13 +1059,6 @@
 Default is '(?n ?e ?o).  Set via `woman-emulation'.")
 
 \f
-;;; Button types:
-
-(define-button-type 'woman-xref
-  'action (lambda (button) (woman (button-label button)))
-  'help-echo "RET, mouse-2: display this man page")
-
-\f
 ;;; Specialized utility functions:
 
 ;;; Fast deletion without saving on the kill ring (cf. simple.el):
@@ -1869,7 +1862,7 @@
     (setq woman-imenu-done nil)
     (if woman-imenu (woman-imenu))
     (setq buffer-read-only nil)
-    (WoMan-highlight-references)
+    (Man-highlight-references)
     (setq buffer-read-only t)
     (set-buffer-modified-p nil)))
 
@@ -1963,21 +1956,6 @@
 	 (time (+ (* (- (car time) (car WoMan-Man-start-time)) 65536)
 		  (- (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."
-  ;; Based on `Man-build-references-alist' in `man'.
-  (when (Man-find-section Man-see-also-regexp)
-    (forward-line 1)
-    (let ((end (save-excursion
-		 (Man-next-section 1)
-		 (point))))
-      (back-to-indentation)
-      (while (re-search-forward Man-reference-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)))))
 
 \f
 ;;; Buffer handling:

Index: man.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/man.el,v
retrieving revision 1.117
diff -u -r1.117 man.el
--- man.el	9 Mar 2003 14:05:25 -0000	1.117
+++ man.el	31 Mar 2003 15:55:32 -0000
@@ -95,6 +95,7 @@
 ;;; Code:
 
 (require 'assoc)
+(require 'button)
 
 ;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
 ;; empty defvars (keep the compiler quiet)
@@ -210,6 +211,12 @@
 		       (string :tag "Real Section")))
   :group 'man)
 
+(defcustom Man-header-file-path
+  '("/usr/include" "/usr/local/include")
+  "C Header file search path used in Man."
+  :type '(repeat string)
+  :group 'man)
+
 (defvar manual-program "man"
   "The name of the program that produces man pages.")
 
@@ -264,6 +271,34 @@
   (concat "\\(" Man-name-regexp "\\)(\\(" Man-section-regexp "\\))")
   "Regular expression describing a reference to another manpage.")
 
+(defvar Man-synopsis-regexp "SYNOPSIS"
+  "Regular expression for SYNOPSIS heading (or your equivalent).
+This regexp should not start with a `^' character.")
+
+(defvar Man-files-regexp "FILES"
+  "Regular expression for FILES heading (or your equivalent).
+This regexp should not start with a `^' character.")
+
+(defvar Man-include-regexp "#[ \t]*include[ \t]*"
+  "Regular expression describing the #include (directive of cpp).")
+ 
+(defvar Man-file-name-regexp "[^<>\" \t\n]+"
+  "Regular expression describing <> in #include line (directive of cpp).")
+
+(defvar Man-normal-file-prefix-regexp "[/~$]"
+  "Regular expression describing a file path appeared in FILES section.")
+
+(defvar Man-header-regexp
+  (concat "\\(" Man-include-regexp "\\)"
+          "[<\"]"
+          "\\(" Man-file-name-regexp "\\)"
+          "[>\"]")
+  "Regular expression describing references to header files.")
+
+(defvar Man-normal-file-regexp
+  (concat Man-normal-file-prefix-regexp Man-file-name-regexp)
+  "Regular expression describing references to normal files.")
+
 ;; This includes the section as an optional part to catch hyphenated
 ;; refernces to manpages.
 (defvar Man-hyphenated-reference-regexp
@@ -333,7 +368,7 @@
 
 (if Man-mode-map
     nil
-  (setq Man-mode-map (make-keymap))
+  (setq Man-mode-map (copy-keymap button-buffer-map))
   (suppress-keymap Man-mode-map)
   (define-key Man-mode-map " "    'scroll-up)
   (define-key Man-mode-map "\177" 'scroll-down)
@@ -350,11 +385,31 @@
   (define-key Man-mode-map "k"    'Man-kill)
   (define-key Man-mode-map "q"    'Man-quit)
   (define-key Man-mode-map "m"    'man)
-  (define-key Man-mode-map "\r"   'man-follow)
-  (define-key Man-mode-map [mouse-2]   'man-follow-mouse)
   (define-key Man-mode-map "?"    'describe-mode)
   )
 
+;; buttons
+(define-button-type 'Man-xref-man-page
+  'action (lambda (button) (man-follow (button-label button)))
+  'help-echo "RET, mouse-2: display this man page")
+
+(define-button-type 'Man-xref-header-file
+  'action (lambda (button) 
+	    (unless (Man-view-header-file (button-get button 'Man-target-string))
+	      (error "Cannot find header file: %s" w)))
+  'help-echo "mouse-2: display this header file")
+
+(define-button-type 'Man-xref-normal-file
+  'action (lambda (button)
+	    (let ((f (substitute-in-file-name
+		      (button-get button 'Man-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
 ;; ======================================================================
 ;; utilities
@@ -562,13 +617,6 @@
       (error "No item under point")
     (man man-args)))
 
-(defun man-follow-mouse (e)
-  "Get a Un*x manual page of the item under the mouse and put it in a buffer."
-  (interactive "e")
-  (save-excursion
-    (mouse-set-point e)
-    (call-interactively 'man-follow)))
-
 (defun Man-getpage-in-background (topic)
   "Use TOPIC to build and fire off the manpage and cleaning command."
   (let* ((man-args topic)
@@ -737,12 +785,41 @@
     (put-text-property (1- (point)) (point) 'face 'bold))
   (goto-char (point-min))
   ;; Try to recognize common forms of cross references.
-  (while (re-search-forward "\\w+([0-9].?)" nil t)
-    (put-text-property (match-beginning 0) (match-end 0)
-		       'mouse-face 'highlight))
+  (Man-highlight-references)
   (Man-softhyphen-to-minus)
   (message "%s man page made up" Man-arguments))
 
+(defun Man-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 ((dummy 0))
+    (Man-highlight-references0
+     Man-see-also-regexp Man-reference-regexp 1 dummy
+     'Man-xref-man-page)
+    (Man-highlight-references0
+     Man-synopsis-regexp Man-header-regexp 0 2
+     'Man-xref-header-file)
+    (Man-highlight-references0
+     Man-files-regexp Man-normal-file-regexp 0 0
+     'Man-xref-normal-file)))
+  
+(defun Man-highlight-references0 (start-section regexp button-pos target-pos type)
+  ;; Based on `Man-build-references-alist'
+  (when (Man-find-section start-section)
+    (forward-line 1)
+    (let ((end (save-excursion
+                 (Man-next-section 1)
+                 (point))))
+      (back-to-indentation)
+      (while (re-search-forward regexp end t)
+	(make-text-button 
+	 (match-beginning button-pos) 
+	 (match-end button-pos)
+	 'type type
+	 'Man-target-string (match-string target-pos)
+	 )))))
+
 (defun Man-cleanup-manpage ()
   "Remove overstriking and underlining from the current buffer."
   (interactive)
@@ -1193,6 +1270,20 @@
     (if Man-circular-pages-flag
 	(Man-goto-page (length Man-page-list))
       (error "You're looking at the first manpage in the buffer"))))
+
+;; Header file support
+(defun Man-view-header-file (file)
+  "View a header file specified by FILE from `Man-header-file-path'."
+  (let ((path Man-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))
 \f
 ;; Init the man package variables, if not already done.
 (Man-init-defvars)

  reply	other threads:[~2003-03-31 15:43 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030401.004318.75810358.jet@gyve.org \
    --to=jet@gyve.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.