yatex

diff yatexhlp.el @ 283:95e8bb2a5c5f

Incorporate tag into dev branch
author HIROSE Yuuji <yuuji@gentei.org>
date Mon, 14 May 2012 21:36:02 +0900
parents 0734be649cb8
children 5921f28ef77c
line diff
     1.1 --- a/yatexhlp.el	Thu Dec 25 04:10:32 2003 +0000
     1.2 +++ b/yatexhlp.el	Mon May 14 21:36:02 2012 +0900
     1.3 @@ -1,8 +1,8 @@
     1.4  ;;; -*- Emacs-Lisp -*-
     1.5  ;;; YaTeX helper with LaTeX commands and macros.
     1.6  ;;; yatexhlp.el
     1.7 -;;; (c)1994,1998 by HIROSE Yuuji.[yuuji@yatex.org]
     1.8 -;;; Last modified Fri Jun 27 12:09:58 2003 on firestorm
     1.9 +;;; (c)1994,1998,2004 by HIROSE Yuuji.[yuuji@yatex.org]
    1.10 +;;; Last modified Tue Oct 19 01:13:21 2004 on firestorm
    1.11  ;;; $Id$
    1.12  
    1.13  (let ((help-file (concat "YATEXHLP."
    1.14 @@ -11,6 +11,8 @@
    1.15        (help-dir
    1.16         (cond
    1.17  	((and (boundp 'site-directory) site-directory) site-directory)
    1.18 +	((string-match "\\.app/" doc-directory)	;For Emacs.app(Darwin)
    1.19 +	 (expand-file-name "../site-lisp" doc-directory))
    1.20  	(YaTeX-emacs-19 (expand-file-name "../../site-lisp" doc-directory))
    1.21  	(t exec-directory))))
    1.22    (defvar YaTeX-help-file
    1.23 @@ -38,6 +40,29 @@
    1.24  	(t "[[ Description ]]"))
    1.25    "Section header of description.")
    1.26  
    1.27 +(defvar YaTeX-help-mode-map nil "Keymap used in YaTeX-help buffer")
    1.28 +(if YaTeX-help-mode-map nil
    1.29 +  (setq YaTeX-help-mode-map (make-sparse-keymap))
    1.30 +  (let ((map YaTeX-help-mode-map))
    1.31 +    (suppress-keymap map)
    1.32 +    (define-key map "j" '(lambda () (interactive) (scroll-up 1)))
    1.33 +    (define-key map "k" '(lambda () (interactive) (scroll-up -1)))
    1.34 +    (define-key map "n" 'next-line)
    1.35 +    (define-key map "p" 'previous-line)
    1.36 +    (define-key map " " 'scroll-up)
    1.37 +    (define-key map "\C-?" 'scroll-down)
    1.38 +    (define-key map "o" 'other-window)
    1.39 +    (define-key map "h" 'describe-bindings)
    1.40 +    (define-key map "q" 'YaTeX-help-quit)
    1.41 +    (define-key map "<" 'beginning-of-buffer)
    1.42 +    (define-key map ">" 'end-of-buffer)))
    1.43 +
    1.44 +(defun YaTeX-help-quit ()
    1.45 +  "Close help and return to privious buffer"
    1.46 +  (interactive)
    1.47 +  (bury-buffer (current-buffer))
    1.48 +  (set-window-configuration YaTeX-help-saved-config))
    1.49 +
    1.50  (defvar YaTeX-help-reference-regexp "<refer\\s +\\([^>]+\\)>"
    1.51    "Regexp of reference format of YaTeX-help file.")
    1.52  (defvar YaTeX-help-buffer "** YaTeX HELP **" "Help buffer name for yatexhlp")
    1.53 @@ -62,10 +87,11 @@
    1.54  		    (or (assoc entry entries)
    1.55  			(setq entries (cons (list entry) entries)))))))))
    1.56         (list YaTeX-help-file YaTeX-help-file-private)))
    1.57 -    entries)
    1.58 -)
    1.59 +    entries))
    1.60  
    1.61 -(defvar YaTeX-help-entries (YaTeX-help-entries))
    1.62 +(defvar YaTeX-help-entries nil
    1.63 +  "Helo entries alist.")
    1.64 +(setq YaTeX-help-entries (YaTeX-help-entries))
    1.65  
    1.66  (defun YaTeX-help-resolve-reference (buffer1 buffer2 &optional done-list)
    1.67    "Replace reference format in buffer1 with refered contents in buffer2."
    1.68 @@ -100,9 +126,7 @@
    1.69  		  (insert-buffer-substring buffer2 beg end))))
    1.70  	  (switch-to-buffer buffer1)))
    1.71        (if beg (YaTeX-help-resolve-reference
    1.72 -	       buffer1 buffer2 (append done-list ref-list))))
    1.73 -    )
    1.74 -)
    1.75 +	       buffer1 buffer2 (append done-list ref-list))))))
    1.76  
    1.77  (defun YaTeX-refer-help (command help-file &optional append)
    1.78    "Refer the COMMAND's help into HELP-FILE.
    1.79 @@ -137,6 +161,7 @@
    1.80        (YaTeX-showup-buffer
    1.81         hbuf (function (lambda (x) (nth 3 (window-edges x)))) t)
    1.82        (set-buffer hbuf)
    1.83 +      (setq buffer-read-only nil)
    1.84        (if append (goto-char (point-max)) (erase-buffer))
    1.85        (insert YaTeX-help-synopsis "\n")
    1.86        (insert-buffer-substring hfbuf sb se)
    1.87 @@ -144,9 +169,18 @@
    1.88        (insert-buffer-substring hfbuf db de)
    1.89        (YaTeX-help-resolve-reference hbuf hfbuf (list (list command)))
    1.90        (goto-char (point-min))
    1.91 +      (setq buffer-read-only t)
    1.92 +      (set-buffer-modified-p nil)
    1.93 +      (YaTeX-help-mode)
    1.94        (select-window curwin)
    1.95 -      t))
    1.96 -)
    1.97 +      t)))
    1.98 +
    1.99 +(defun YaTeX-help-mode ()
   1.100 +  (interactive)
   1.101 +  (use-local-map YaTeX-help-mode-map)
   1.102 +  (setq major-mode 'yatex-help-mode
   1.103 +	mode-name "YaTeX-HELP"))
   1.104 +
   1.105  (defun YaTeX-help-newline (&optional arg)
   1.106    (interactive "P")
   1.107    (if (and (= (current-column) 1) (= (preceding-char) ?.) (eolp))
   1.108 @@ -158,8 +192,8 @@
   1.109  	   YaTeX-help-command-current YaTeX-help-file-current))
   1.110  	(set-window-configuration YaTeX-help-saved-config)
   1.111  	(bury-buffer cbuf))
   1.112 -    (newline arg))
   1.113 -)
   1.114 +    (newline arg)))
   1.115 +
   1.116  (defun YaTeX-help-add-entry (command help-file)
   1.117    (let ((hfbuf (find-file-noselect help-file))
   1.118  	(dbuf (current-buffer)) beg end)
   1.119 @@ -185,8 +219,8 @@
   1.120      (let ((make-backup-files t))
   1.121        (basic-save-buffer))
   1.122      (bury-buffer hfbuf)
   1.123 -    (setq YaTeX-help-entries (cons (list command) YaTeX-help-entries)))
   1.124 -)
   1.125 +    (setq YaTeX-help-entries (cons (list command) YaTeX-help-entries))))
   1.126 +
   1.127  (defun YaTeX-help-prepare-entry (command help-file)
   1.128    "Read help description on COMMAND and add it to HELP-FILE."
   1.129    (let ((buf (get-buffer-create "**Description**"))
   1.130 @@ -207,16 +241,15 @@
   1.131      (use-local-map YaTeX-help-entry-map)
   1.132      (message
   1.133       (cond (YaTeX-japan "入力を終えたら . のみ入力してRET")
   1.134 -	   (t "Type only `.' and RET to exit."))))
   1.135 -)
   1.136 +	   (t "Type only `.' and RET to exit.")))))
   1.137 +
   1.138  (defun YaTeX-enrich-help (command)
   1.139    "Add the COMMAND's help to help file."
   1.140    (if (y-or-n-p (format "No help on `%s'. Create help?" command))
   1.141        (YaTeX-help-prepare-entry
   1.142         command
   1.143         (if (y-or-n-p "Add help to global documentation?")
   1.144 -	   YaTeX-help-file YaTeX-help-file-private)))
   1.145 -)
   1.146 +	   YaTeX-help-file YaTeX-help-file-private))))
   1.147  
   1.148  (defun YaTeX-help-sort (&optional help-file)
   1.149    "Sort help file HELP-FILE.
   1.150 @@ -225,8 +258,7 @@
   1.151    (interactive)
   1.152    (if help-file (set-buffer (find-file-noselect help-file)))
   1.153    (sort-regexp-fields
   1.154 -   nil "\\(\\sw+\\)\\([^]+\\|\\s'\\)" "\\1" (point-min) (point-max))
   1.155 -)
   1.156 +   nil "\\(\\sw+\\)\\([^]+\\|\\s'\\)" "\\1" (point-min) (point-max)))
   1.157  
   1.158  (defun YaTeX-apropos-file (keyword help-file &optional append)
   1.159    (let ((hb (find-file-noselect help-file))
   1.160 @@ -238,6 +270,7 @@
   1.161       ab (function (lambda (x) (nth 3 (window-edges x)))))
   1.162      (select-window (get-buffer-window ab))
   1.163      (set-buffer ab)			;assertion
   1.164 +    (setq buffer-read-only nil)
   1.165      (or append (erase-buffer))
   1.166      (set-buffer hb)
   1.167      (goto-char (point-min))
   1.168 @@ -250,22 +283,23 @@
   1.169        (insert-char ?- (1- (window-width)))
   1.170        (insert (format "\n<<%s>>\n" command))
   1.171        (YaTeX-refer-help command help-file t) ;append mode
   1.172 +      (setq buffer-read-only nil)
   1.173        (set-buffer hb)
   1.174        (goto-char pt)
   1.175        (if (re-search-forward head nil 1)
   1.176  	  (goto-char (1- (match-beginning 0)))))
   1.177 +    (setq buffer-read-only t)
   1.178      (select-window sw)
   1.179 -    pt)
   1.180 -)
   1.181 +    pt))
   1.182  
   1.183  ;;;###autoload
   1.184  (defun YaTeX-apropos (key)
   1.185    (interactive "sLaTeX apropos (regexp): ")
   1.186    (if (string= "" key) (error "Nothing to show"))
   1.187 +  (setq YaTeX-help-saved-config (current-window-configuration))
   1.188    (or (YaTeX-apropos-file key YaTeX-help-file)
   1.189        (YaTeX-apropos-file key YaTeX-help-file-private t)
   1.190 -      (message "No matches found."))
   1.191 -)
   1.192 +      (message "No matches found.")))
   1.193  
   1.194  ;;;###autoload
   1.195  (defun YaTeX-help ()
   1.196 @@ -301,7 +335,7 @@
   1.197  	     "Describe (La)TeX command: "
   1.198  	     YaTeX-help-entries nil nil command))
   1.199        );end excursion
   1.200 +    (setq YaTeX-help-saved-config (current-window-configuration))
   1.201      (or (YaTeX-refer-help command YaTeX-help-file)
   1.202  	(YaTeX-refer-help command YaTeX-help-file-private)
   1.203 -	(YaTeX-enrich-help command)))
   1.204 -)
   1.205 +	(YaTeX-enrich-help command))))