From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#17831: 24.4.50; bad default value for `Man-width' Date: Fri, 27 Jun 2014 02:49:55 +0300 Organization: JURTA Message-ID: <87y4wj9pzs.fsf@mail.jurta.org> References: <87tx7buryg.fsf@mail.jurta.org> <53A92532.9040901@gmx.at> <83zjh2qpia.fsf@gnu.org> <83mwd2qji7.fsf@gnu.org> <83ha3aqdh5.fsf@gnu.org> <87tx79es0g.fsf@mail.jurta.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1403830177 5054 80.91.229.3 (27 Jun 2014 00:49:37 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 27 Jun 2014 00:49:37 +0000 (UTC) Cc: 17831@debbugs.gnu.org, sdl.web@gmail.com To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Jun 27 02:49:29 2014 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1X0KM2-0004ig-KR for geb-bug-gnu-emacs@m.gmane.org; Fri, 27 Jun 2014 02:49:26 +0200 Original-Received: from localhost ([::1]:47528 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X0KM2-0008IV-BC for geb-bug-gnu-emacs@m.gmane.org; Thu, 26 Jun 2014 20:49:26 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47521) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X0KLs-00085r-3B for bug-gnu-emacs@gnu.org; Thu, 26 Jun 2014 20:49:23 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X0KLg-0000yk-3c for bug-gnu-emacs@gnu.org; Thu, 26 Jun 2014 20:49:16 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:42967) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X0KLg-0000ye-0C for bug-gnu-emacs@gnu.org; Thu, 26 Jun 2014 20:49:04 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1X0KLf-0002V3-O4 for bug-gnu-emacs@gnu.org; Thu, 26 Jun 2014 20:49:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 27 Jun 2014 00:49:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 17831 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 17831-submit@debbugs.gnu.org id=B17831.14038301029505 (code B ref 17831); Fri, 27 Jun 2014 00:49:03 +0000 Original-Received: (at 17831) by debbugs.gnu.org; 27 Jun 2014 00:48:22 +0000 Original-Received: from localhost ([127.0.0.1]:34110 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1X0KL0-0002TD-5l for submit@debbugs.gnu.org; Thu, 26 Jun 2014 20:48:22 -0400 Original-Received: from alc-vshost7.dreamhost.com ([69.163.216.107]:54913 helo=ps18281.dreamhostps.com) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1X0KKw-0002Su-Hl for 17831@debbugs.gnu.org; Thu, 26 Jun 2014 20:48:19 -0400 Original-Received: from localhost.jurta.org (ps18281.dreamhostps.com [69.163.222.226]) by ps18281.dreamhostps.com (Postfix) with ESMTP id 0765C304DCE7EF; Thu, 26 Jun 2014 17:48:15 -0700 (PDT) In-Reply-To: (Stefan Monnier's message of "Tue, 24 Jun 2014 23:11:02 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (x86_64-pc-linux-gnu) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:90871 Archived-At: >> This simple patch displays the buffer immediately, >> but then slowly fills it with unformatted output >> that doesn't look nice. > > Indeed, that's why I haven't made this change in Emacs years ago (when > I made it in my local copy after getting too annoyed at the window-popup > disruption). The solution is obvious, tho: "Just" move the reformatting > to the process-filter. Using the same approach like processing escape sequences in grep/compilation produces a nice result for M-x man: it displays the first formatted page immediately and continues formatting the rest of the man page in background. There are still small details to iron out but this is basically achieved with the following patch. There is one problem that I noticed on large man pages: formatting small chunks by process-filter is little slower than formatting the whole output like it currently does. Could it be possible that a slowdown is caused by `narrow-to-region'? Then it's possible to add two new arguments `min' and `max' to `Man-fontify-manpage' to limit the processed region manually instead of using narrowing. === modified file 'lisp/man.el' --- lisp/man.el 2014-05-09 07:02:00 +0000 +++ lisp/man.el 2014-06-27 00:49:22 +0000 @@ -1056,20 +1056,22 @@ (defun Man-getpage-in-background (topic) (require 'env) (message "Invoking %s %s in the background" manual-program man-args) (setq buffer (generate-new-buffer bufname)) + (Man-notify-when-ready buffer) (with-current-buffer buffer (setq buffer-undo-list t) (setq Man-original-frame (selected-frame)) (setq Man-arguments man-args)) (Man-start-calling (if (fboundp 'start-process) - (set-process-sentinel - (start-process manual-program buffer - (if (memq system-type '(cygwin windows-nt)) - shell-file-name - "sh") - shell-command-switch - (format (Man-build-man-command) man-args)) - 'Man-bgproc-sentinel) + (let ((proc (start-process + manual-program buffer + (if (memq system-type '(cygwin windows-nt)) + shell-file-name + "sh") + shell-command-switch + (format (Man-build-man-command) man-args)))) + (set-process-sentinel proc 'Man-bgproc-sentinel) + (set-process-filter proc 'Man-bgproc-filter)) (let ((exit-status (call-process shell-file-name nil (list buffer nil) nil shell-command-switch @@ -1312,6 +1317,33 @@ (defun Man-cleanup-manpage (&optional in (Man-softhyphen-to-minus) (message "%s man page cleaned up" Man-arguments)) +(defun Man-bgproc-filter (process string) + "Manpage background process filter. +When manpage command is run asynchronously, PROCESS is the process +object for the manpage command; when manpage command is run +synchronously, PROCESS is the name of the buffer where the manpage +command is run. Second argument STRING is the entire string of output." + (save-excursion + (let ((Man-buffer (if (stringp process) (get-buffer process) + (process-buffer process)))) + (if (null (buffer-name Man-buffer)) ;; deleted buffer + (or (stringp process) + (set-process-buffer process nil)) + + (with-current-buffer Man-buffer + (let ((inhibit-read-only t) + (beg (marker-position (process-mark process)))) + (goto-char beg) + (insert string) + (save-restriction + (narrow-to-region + (save-excursion (goto-char beg) (line-beginning-position)) + (point)) + (if Man-fontify-manpage-flag + (Man-fontify-manpage) + (Man-cleanup-manpage))) + (set-marker (process-mark process) (point-max)))))))) + (defun Man-bgproc-sentinel (process msg) "Manpage background process sentinel. When manpage command is run asynchronously, PROCESS is the process @@ -1365,9 +1398,6 @@ (defun Man-bgproc-sentinel (process msg) )) (if delete-buff (kill-buffer Man-buffer) - (if Man-fontify-manpage-flag - (Man-fontify-manpage) - (Man-cleanup-manpage)) (run-hooks 'Man-cooked-hook) (Man-mode) @@ -1378,11 +1408,6 @@ (defun Man-bgproc-sentinel (process msg) (user-error "Can't find the %s manpage" (Man-page-from-arguments args))) (set-buffer-modified-p nil)))) - ;; Restore case-fold-search before calling - ;; Man-notify-when-ready because it may switch buffers. - - (if (not delete-buff) - (Man-notify-when-ready Man-buffer)) (if err-mess (error "%s" err-mess))