emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] trunk r115023: * lisp/man.el (Man-start-calling): New macr


From: Stefan Monnier
Subject: [Emacs-diffs] trunk r115023: * lisp/man.el (Man-start-calling): New macro, extracted from
Date: Fri, 08 Nov 2013 04:10:02 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 115023
revision-id: address@hidden
parent: address@hidden
author: Darren Hoo <address@hidden>
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Thu 2013-11-07 23:09:56 -0500
message:
  * 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.
modified:
  lisp/ChangeLog                 changelog-20091113204419-o5vbwnq5f7feedwu-1432
  lisp/man.el                    man.el-20091113204419-o5vbwnq5f7feedwu-582
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2013-11-08 02:31:51 +0000
+++ b/lisp/ChangeLog    2013-11-08 04:09:56 +0000
@@ -1,3 +1,11 @@
+2013-11-08  Darren Hoo  <address@hidden>
+
+       * 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.
+
 2013-11-08  Dmitry Gutov  <address@hidden>
 
        * progmodes/ruby-mode.el (ruby-smie-grammar): Improve precedences
@@ -5,8 +13,8 @@
        (ruby-smie--args-separator-p): Prohibit keyword "do" as the first
        argument.  Prohibit opening curly brace because it could only be a
        block opener in that position.
-       (ruby-smie--forward-token, ruby-smie--backward-token): Separate
-       "|" from "&" or "*" going after it.  That can happen in block
+       (ruby-smie--forward-token, ruby-smie--backward-token):
+       Separate "|" from "&" or "*" going after it.  That can happen in block
        arguments.
        (ruby-smie--indent-to-stmt): New function, seeks the end of
        previous statement or beginning of buffer.

=== modified file 'lisp/man.el'
--- a/lisp/man.el       2013-10-27 02:02:02 +0000
+++ b/lisp/man.el       2013-11-08 04:09:56 +0000
@@ -448,6 +448,7 @@
     (define-key map "s"    'Man-goto-see-also-section)
     (define-key map "k"    'Man-kill)
     (define-key map "q"    'Man-quit)
+    (define-key map "u"    'Man-update-manpage)
     (define-key map "m"    'man)
     ;; Not all the man references get buttons currently.  The text in the
     ;; manual page can contain references to other man pages
@@ -1000,6 +1001,52 @@
       (error "No item under point")
     (man man-args)))
 
+(defmacro Man-start-calling (&rest body)
+  "Start the man command in `body' after setting up the environment"
+  `(let ((process-environment (copy-sequence process-environment))
+       ;; The following is so Awk script gets \n intact
+       ;; But don't prevent decoding of the outside.
+       (coding-system-for-write 'raw-text-unix)
+       ;; We must decode the output by a coding system that the
+       ;; system's locale suggests in multibyte mode.
+       (coding-system-for-read locale-coding-system)
+       ;; Avoid possible error by using a directory that always exists.
+       (default-directory
+         (if (and (file-directory-p default-directory)
+                  (not (find-file-name-handler default-directory
+                                               'file-directory-p)))
+             default-directory
+           "/")))
+    ;; Prevent any attempt to use display terminal fanciness.
+    (setenv "TERM" "dumb")
+    ;; In Debian Woody, at least, we get overlong lines under X
+    ;; unless COLUMNS or MANWIDTH is set.  This isn't a problem on
+    ;; a tty.  man(1) says:
+    ;;        MANWIDTH
+    ;;               If $MANWIDTH is set, its value is used as the  line
+    ;;               length  for which manual pages should be formatted.
+    ;;               If it is not set, manual pages  will  be  formatted
+    ;;               with  a line length appropriate to the current ter-
+    ;;               minal (using an ioctl(2) if available, the value of
+    ;;               $COLUMNS,  or falling back to 80 characters if nei-
+    ;;               ther is available).
+    (when (or window-system
+             (not (or (getenv "MANWIDTH") (getenv "COLUMNS"))))
+      ;; This isn't strictly correct, since we don't know how
+      ;; the page will actually be displayed, but it seems
+      ;; reasonable.
+      (setenv "COLUMNS" (number-to-string
+                        (cond
+                         ((and (integerp Man-width) (> Man-width 0))
+                          Man-width)
+                         (Man-width (frame-width))
+                         ((window-width))))))
+    ;; Since man-db 2.4.3-1, man writes plain text with no escape
+    ;; sequences when stdout is not a tty.     In 2.5.0, the following
+    ;; env-var was added to allow control of this (see Debian Bug#340673).
+    (setenv "MAN_KEEP_FORMATTING" "1")
+    ,@body))
+
 (defun Man-getpage-in-background (topic)
   "Use TOPIC to build and fire off the manpage and cleaning command.
 Return the buffer in which the manpage will appear."
@@ -1015,51 +1062,8 @@
        (setq buffer-undo-list t)
        (setq Man-original-frame (selected-frame))
        (setq Man-arguments man-args))
-      (let ((process-environment (copy-sequence process-environment))
-           ;; The following is so Awk script gets \n intact
-           ;; But don't prevent decoding of the outside.
-           (coding-system-for-write 'raw-text-unix)
-           ;; We must decode the output by a coding system that the
-           ;; system's locale suggests in multibyte mode.
-           (coding-system-for-read
-            (if (default-value 'enable-multibyte-characters)
-                locale-coding-system 'raw-text-unix))
-           ;; Avoid possible error by using a directory that always exists.
-           (default-directory
-             (if (and (file-directory-p default-directory)
-                      (not (find-file-name-handler default-directory
-                                                   'file-directory-p)))
-                 default-directory
-               "/")))
-       ;; Prevent any attempt to use display terminal fanciness.
-       (setenv "TERM" "dumb")
-       ;; In Debian Woody, at least, we get overlong lines under X
-       ;; unless COLUMNS or MANWIDTH is set.  This isn't a problem on
-       ;; a tty.  man(1) says:
-       ;;        MANWIDTH
-       ;;               If $MANWIDTH is set, its value is used as the  line
-       ;;               length  for which manual pages should be formatted.
-       ;;               If it is not set, manual pages  will  be  formatted
-       ;;               with  a line length appropriate to the current ter-
-       ;;               minal (using an ioctl(2) if available, the value of
-       ;;               $COLUMNS,  or falling back to 80 characters if nei-
-       ;;               ther is available).
-       (when (or window-system
-                  (not (or (getenv "MANWIDTH") (getenv "COLUMNS"))))
-         ;; This isn't strictly correct, since we don't know how
-         ;; the page will actually be displayed, but it seems
-         ;; reasonable.
-         (setenv "COLUMNS" (number-to-string
-                            (cond
-                             ((and (integerp Man-width) (> Man-width 0))
-                              Man-width)
-                             (Man-width (frame-width))
-                             ((window-width))))))
-       ;; Since man-db 2.4.3-1, man writes plain text with no escape
-       ;; sequences when stdout is not a tty.  In 2.5.0, the following
-       ;; env-var was added to allow control of this (see Debian Bug#340673).
-       (setenv "MAN_KEEP_FORMATTING" "1")
-       (if (fboundp 'start-process)
+      (Man-start-calling
+       (if (fboundp 'start-process)
            (set-process-sentinel
             (start-process manual-program buffer
                            (if (memq system-type '(cygwin windows-nt))
@@ -1081,7 +1085,34 @@
                                   exit-status)))
                (setq msg exit-status))
            (Man-bgproc-sentinel bufname msg)))))
-    buffer))
+      buffer))
+
+(defun Man-update-manpage ()
+  "Reformat current manpage by calling the man command again synchronously."
+  (interactive)
+  (when (eq Man-arguments nil)
+    ;;this shouldn't happen unless it is not in a Man buffer."
+    (error "Man-arguments not initialized"))
+  (let ((old-pos (point))
+       (text (current-word))
+       (old-size (buffer-size))
+       (inhibit-read-only t)
+       (buffer-read-only nil))
+     (erase-buffer)
+     (Man-start-calling
+      (call-process shell-file-name nil (list (current-buffer) nil) nil
+                   shell-command-switch
+                   (format (Man-build-man-command) Man-arguments)))
+     (if Man-fontify-manpage-flag
+        (Man-fontify-manpage)
+       (Man-cleanup-manpage))
+     (goto-char old-pos)
+     ;;restore the point, not strictly right.
+     (unless (or (eq text nil) (= old-size (buffer-size)))
+       (let ((case-fold-search nil))
+        (if (> old-size (buffer-size))
+            (search-backward text nil t))
+        (search-forward text nil t)))))
 
 (defun Man-notify-when-ready (man-buffer)
   "Notify the user when MAN-BUFFER is ready.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]