aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarren Hoo2013-11-07 23:09:56 -0500
committerStefan Monnier2013-11-07 23:09:56 -0500
commitdaddb3fd8355bce563d1b70eb372d978db912704 (patch)
tree6ac92cb7008868560665fbb95f550bd929e24f7f
parentd85783ca32212bba9d43e28748d0a612eaf197b9 (diff)
downloademacs-daddb3fd8355bce563d1b70eb372d978db912704.tar.gz
emacs-daddb3fd8355bce563d1b70eb372d978db912704.zip
* lisp/man.el (Man-start-calling): New macro, extracted from
Man-getpage-in-background. (Man-getpage-in-background): Use it. (Man-update-manpage): New command. (Man-mode-map): Bind it.
-rw-r--r--lisp/ChangeLog12
-rw-r--r--lisp/man.el123
2 files changed, 87 insertions, 48 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index f1c25984a54..7cc658d9e24 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,11 @@
12013-11-08 Darren Hoo <darren.hoo@gmail.com>
2
3 * man.el (Man-start-calling): New macro, extracted from
4 Man-getpage-in-background.
5 (Man-getpage-in-background): Use it.
6 (Man-update-manpage): New command.
7 (Man-mode-map): Bind it.
8
12013-11-08 Dmitry Gutov <dgutov@yandex.ru> 92013-11-08 Dmitry Gutov <dgutov@yandex.ru>
2 10
3 * progmodes/ruby-mode.el (ruby-smie-grammar): Improve precedences 11 * progmodes/ruby-mode.el (ruby-smie-grammar): Improve precedences
@@ -5,8 +13,8 @@
5 (ruby-smie--args-separator-p): Prohibit keyword "do" as the first 13 (ruby-smie--args-separator-p): Prohibit keyword "do" as the first
6 argument. Prohibit opening curly brace because it could only be a 14 argument. Prohibit opening curly brace because it could only be a
7 block opener in that position. 15 block opener in that position.
8 (ruby-smie--forward-token, ruby-smie--backward-token): Separate 16 (ruby-smie--forward-token, ruby-smie--backward-token):
9 "|" from "&" or "*" going after it. That can happen in block 17 Separate "|" from "&" or "*" going after it. That can happen in block
10 arguments. 18 arguments.
11 (ruby-smie--indent-to-stmt): New function, seeks the end of 19 (ruby-smie--indent-to-stmt): New function, seeks the end of
12 previous statement or beginning of buffer. 20 previous statement or beginning of buffer.
diff --git a/lisp/man.el b/lisp/man.el
index bea53c6addd..a03fda5e6bd 100644
--- a/lisp/man.el
+++ b/lisp/man.el
@@ -448,6 +448,7 @@ Otherwise, the value is whatever the function
448 (define-key map "s" 'Man-goto-see-also-section) 448 (define-key map "s" 'Man-goto-see-also-section)
449 (define-key map "k" 'Man-kill) 449 (define-key map "k" 'Man-kill)
450 (define-key map "q" 'Man-quit) 450 (define-key map "q" 'Man-quit)
451 (define-key map "u" 'Man-update-manpage)
451 (define-key map "m" 'man) 452 (define-key map "m" 'man)
452 ;; Not all the man references get buttons currently. The text in the 453 ;; Not all the man references get buttons currently. The text in the
453 ;; manual page can contain references to other man pages 454 ;; manual page can contain references to other man pages
@@ -1000,6 +1001,52 @@ names or descriptions. The pattern argument is usually an
1000 (error "No item under point") 1001 (error "No item under point")
1001 (man man-args))) 1002 (man man-args)))
1002 1003
1004(defmacro Man-start-calling (&rest body)
1005 "Start the man command in `body' after setting up the environment"
1006 `(let ((process-environment (copy-sequence process-environment))
1007 ;; The following is so Awk script gets \n intact
1008 ;; But don't prevent decoding of the outside.
1009 (coding-system-for-write 'raw-text-unix)
1010 ;; We must decode the output by a coding system that the
1011 ;; system's locale suggests in multibyte mode.
1012 (coding-system-for-read locale-coding-system)
1013 ;; Avoid possible error by using a directory that always exists.
1014 (default-directory
1015 (if (and (file-directory-p default-directory)
1016 (not (find-file-name-handler default-directory
1017 'file-directory-p)))
1018 default-directory
1019 "/")))
1020 ;; Prevent any attempt to use display terminal fanciness.
1021 (setenv "TERM" "dumb")
1022 ;; In Debian Woody, at least, we get overlong lines under X
1023 ;; unless COLUMNS or MANWIDTH is set. This isn't a problem on
1024 ;; a tty. man(1) says:
1025 ;; MANWIDTH
1026 ;; If $MANWIDTH is set, its value is used as the line
1027 ;; length for which manual pages should be formatted.
1028 ;; If it is not set, manual pages will be formatted
1029 ;; with a line length appropriate to the current ter-
1030 ;; minal (using an ioctl(2) if available, the value of
1031 ;; $COLUMNS, or falling back to 80 characters if nei-
1032 ;; ther is available).
1033 (when (or window-system
1034 (not (or (getenv "MANWIDTH") (getenv "COLUMNS"))))
1035 ;; This isn't strictly correct, since we don't know how
1036 ;; the page will actually be displayed, but it seems
1037 ;; reasonable.
1038 (setenv "COLUMNS" (number-to-string
1039 (cond
1040 ((and (integerp Man-width) (> Man-width 0))
1041 Man-width)
1042 (Man-width (frame-width))
1043 ((window-width))))))
1044 ;; Since man-db 2.4.3-1, man writes plain text with no escape
1045 ;; sequences when stdout is not a tty. In 2.5.0, the following
1046 ;; env-var was added to allow control of this (see Debian Bug#340673).
1047 (setenv "MAN_KEEP_FORMATTING" "1")
1048 ,@body))
1049
1003(defun Man-getpage-in-background (topic) 1050(defun Man-getpage-in-background (topic)
1004 "Use TOPIC to build and fire off the manpage and cleaning command. 1051 "Use TOPIC to build and fire off the manpage and cleaning command.
1005Return the buffer in which the manpage will appear." 1052Return the buffer in which the manpage will appear."
@@ -1015,51 +1062,8 @@ Return the buffer in which the manpage will appear."
1015 (setq buffer-undo-list t) 1062 (setq buffer-undo-list t)
1016 (setq Man-original-frame (selected-frame)) 1063 (setq Man-original-frame (selected-frame))
1017 (setq Man-arguments man-args)) 1064 (setq Man-arguments man-args))
1018 (let ((process-environment (copy-sequence process-environment)) 1065 (Man-start-calling
1019 ;; The following is so Awk script gets \n intact 1066 (if (fboundp 'start-process)
1020 ;; But don't prevent decoding of the outside.
1021 (coding-system-for-write 'raw-text-unix)
1022 ;; We must decode the output by a coding system that the
1023 ;; system's locale suggests in multibyte mode.
1024 (coding-system-for-read
1025 (if (default-value 'enable-multibyte-characters)
1026 locale-coding-system 'raw-text-unix))
1027 ;; Avoid possible error by using a directory that always exists.
1028 (default-directory
1029 (if (and (file-directory-p default-directory)
1030 (not (find-file-name-handler default-directory
1031 'file-directory-p)))
1032 default-directory
1033 "/")))
1034 ;; Prevent any attempt to use display terminal fanciness.
1035 (setenv "TERM" "dumb")
1036 ;; In Debian Woody, at least, we get overlong lines under X
1037 ;; unless COLUMNS or MANWIDTH is set. This isn't a problem on
1038 ;; a tty. man(1) says:
1039 ;; MANWIDTH
1040 ;; If $MANWIDTH is set, its value is used as the line
1041 ;; length for which manual pages should be formatted.
1042 ;; If it is not set, manual pages will be formatted
1043 ;; with a line length appropriate to the current ter-
1044 ;; minal (using an ioctl(2) if available, the value of
1045 ;; $COLUMNS, or falling back to 80 characters if nei-
1046 ;; ther is available).
1047 (when (or window-system
1048 (not (or (getenv "MANWIDTH") (getenv "COLUMNS"))))
1049 ;; This isn't strictly correct, since we don't know how
1050 ;; the page will actually be displayed, but it seems
1051 ;; reasonable.
1052 (setenv "COLUMNS" (number-to-string
1053 (cond
1054 ((and (integerp Man-width) (> Man-width 0))
1055 Man-width)
1056 (Man-width (frame-width))
1057 ((window-width))))))
1058 ;; Since man-db 2.4.3-1, man writes plain text with no escape
1059 ;; sequences when stdout is not a tty. In 2.5.0, the following
1060 ;; env-var was added to allow control of this (see Debian Bug#340673).
1061 (setenv "MAN_KEEP_FORMATTING" "1")
1062 (if (fboundp 'start-process)
1063 (set-process-sentinel 1067 (set-process-sentinel
1064 (start-process manual-program buffer 1068 (start-process manual-program buffer
1065 (if (memq system-type '(cygwin windows-nt)) 1069 (if (memq system-type '(cygwin windows-nt))
@@ -1081,7 +1085,34 @@ Return the buffer in which the manpage will appear."
1081 exit-status))) 1085 exit-status)))
1082 (setq msg exit-status)) 1086 (setq msg exit-status))
1083 (Man-bgproc-sentinel bufname msg))))) 1087 (Man-bgproc-sentinel bufname msg)))))
1084 buffer)) 1088 buffer))
1089
1090(defun Man-update-manpage ()
1091 "Reformat current manpage by calling the man command again synchronously."
1092 (interactive)
1093 (when (eq Man-arguments nil)
1094 ;;this shouldn't happen unless it is not in a Man buffer."
1095 (error "Man-arguments not initialized"))
1096 (let ((old-pos (point))
1097 (text (current-word))
1098 (old-size (buffer-size))
1099 (inhibit-read-only t)
1100 (buffer-read-only nil))
1101 (erase-buffer)
1102 (Man-start-calling
1103 (call-process shell-file-name nil (list (current-buffer) nil) nil
1104 shell-command-switch
1105 (format (Man-build-man-command) Man-arguments)))
1106 (if Man-fontify-manpage-flag
1107 (Man-fontify-manpage)
1108 (Man-cleanup-manpage))
1109 (goto-char old-pos)
1110 ;;restore the point, not strictly right.
1111 (unless (or (eq text nil) (= old-size (buffer-size)))
1112 (let ((case-fold-search nil))
1113 (if (> old-size (buffer-size))
1114 (search-backward text nil t))
1115 (search-forward text nil t)))))
1085 1116
1086(defun Man-notify-when-ready (man-buffer) 1117(defun Man-notify-when-ready (man-buffer)
1087 "Notify the user when MAN-BUFFER is ready. 1118 "Notify the user when MAN-BUFFER is ready.