comparison lisp/man.el @ 16973:39569e1b84b2

(Man-build-man-command): When async processes aren't supported, don't redirect stderr via the shell. (Man-getpage-in-background, Man-bgproc-sentinel): Support for systems where async processes don't work.
author Eli Zaretskii <eliz@gnu.org>
date Mon, 03 Feb 1997 18:02:26 +0000
parents 75d463b202b5
children f4eb94106c89
comparison
equal deleted inserted replaced
16972:99de1dc68184 16973:39569e1b84b2
395 Man-current-page 395 Man-current-page
396 (length Man-page-list))) 396 (length Man-page-list)))
397 397
398 (defsubst Man-build-man-command () 398 (defsubst Man-build-man-command ()
399 "Builds the entire background manpage and cleaning command." 399 "Builds the entire background manpage and cleaning command."
400 (let ((command (concat manual-program " " Man-switches " %s 2>/dev/null")) 400 (let ((command (concat manual-program " " Man-switches
401 ; Stock MS-DOS shells cannot redirect stderr;
402 ; `call-process' below sends it to /dev/null,
403 ; so we don't need `2>' even with DOS shells
404 ; which do support stderr redirection.
405 (if (not (fboundp 'start-process))
406 " %s"
407 " %s 2>/dev/null")))
401 (flist Man-filter-list)) 408 (flist Man-filter-list))
402 (while (and flist (car flist)) 409 (while (and flist (car flist))
403 (let ((pcom (car (car flist))) 410 (let ((pcom (car (car flist)))
404 (pargs (cdr (car flist)))) 411 (pargs (cdr (car flist))))
405 (setq command 412 (setq command
532 (setq Man-original-frame (selected-frame)) 539 (setq Man-original-frame (selected-frame))
533 (setq Man-arguments man-args)) 540 (setq Man-arguments man-args))
534 (let ((process-environment (copy-sequence process-environment))) 541 (let ((process-environment (copy-sequence process-environment)))
535 ;; Prevent any attempt to use display terminal fanciness. 542 ;; Prevent any attempt to use display terminal fanciness.
536 (setenv "TERM" "dumb") 543 (setenv "TERM" "dumb")
537 (set-process-sentinel 544 (if (fboundp 'start-process)
538 (start-process manual-program buffer "sh" "-c" 545 (set-process-sentinel
539 (format (Man-build-man-command) man-args)) 546 (start-process manual-program buffer "sh" "-c"
540 'Man-bgproc-sentinel))))) 547 (format (Man-build-man-command) man-args))
548 'Man-bgproc-sentinel)
549 (progn
550 (let ((exit-status
551 (call-process shell-file-name nil (list buffer nil) nil "-c"
552 (format (Man-build-man-command) man-args)))
553 (msg ""))
554 (or (and (numberp exit-status)
555 (= exit-status 0))
556 (and (numberp exit-status)
557 (setq msg
558 (format "exited abnormally with code %d"
559 exit-status)))
560 (setq msg exit-status))
561 (Man-bgproc-sentinel bufname msg))))))))
541 562
542 (defun Man-notify-when-ready (man-buffer) 563 (defun Man-notify-when-ready (man-buffer)
543 "Notify the user when MAN-BUFFER is ready. 564 "Notify the user when MAN-BUFFER is ready.
544 See the variable `Man-notify-method' for the different notification behaviors." 565 See the variable `Man-notify-method' for the different notification behaviors."
545 (let ((saved-frame (save-excursion 566 (let ((saved-frame (save-excursion
645 (goto-char (point-min)) 666 (goto-char (point-min))
646 (while (search-forward "\255" nil t) (replace-match "-")) 667 (while (search-forward "\255" nil t) (replace-match "-"))
647 (message "%s man page cleaned up" Man-arguments)) 668 (message "%s man page cleaned up" Man-arguments))
648 669
649 (defun Man-bgproc-sentinel (process msg) 670 (defun Man-bgproc-sentinel (process msg)
650 "Manpage background process sentinel." 671 "Manpage background process sentinel.
651 (let ((Man-buffer (process-buffer process)) 672 When manpage command is run asynchronously, PROCESS is the process
673 object for the manpage command; when manpage command is run
674 synchronously, PROCESS is the name of the buffer where the manpage
675 command is run. Second argument MSG is the exit message of the
676 manpage command."
677 (let ((Man-buffer (if (stringp process) (get-buffer process)
678 (process-buffer process)))
652 (delete-buff nil) 679 (delete-buff nil)
653 (err-mess nil)) 680 (err-mess nil))
654 681
655 (if (null (buffer-name Man-buffer)) ;; deleted buffer 682 (if (null (buffer-name Man-buffer)) ;; deleted buffer
656 (set-process-buffer process nil) 683 (or (stringp process)
684 (set-process-buffer process nil))
657 685
658 (save-excursion 686 (save-excursion
659 (set-buffer Man-buffer) 687 (set-buffer Man-buffer)
660 (let ((case-fold-search nil)) 688 (let ((case-fold-search nil))
661 (goto-char (point-min)) 689 (goto-char (point-min))
663 (looking-at "[^\n]*: nothing appropriate$")) 691 (looking-at "[^\n]*: nothing appropriate$"))
664 (setq err-mess (buffer-substring (point) 692 (setq err-mess (buffer-substring (point)
665 (progn 693 (progn
666 (end-of-line) (point))) 694 (end-of-line) (point)))
667 delete-buff t)) 695 delete-buff t))
668 ((not (and (eq (process-status process) 'exit) 696 ((or (stringp process)
669 (= (process-exit-status process) 0))) 697 (not (and (eq (process-status process) 'exit)
670 (setq err-mess 698 (= (process-exit-status process) 0))))
671 (concat (buffer-name Man-buffer) 699 (or (zerop (length msg))
672 ": process " 700 (progn
673 (let ((eos (1- (length msg)))) 701 (setq err-mess
674 (if (= (aref msg eos) ?\n) 702 (concat (buffer-name Man-buffer)
675 (substring msg 0 eos) msg)))) 703 ": process "
676 (goto-char (point-max)) 704 (let ((eos (1- (length msg))))
677 (insert (format "\nprocess %s" msg)) 705 (if (= (aref msg eos) ?\n)
678 ))) 706 (substring msg 0 eos) msg))))
707 (goto-char (point-max))
708 (insert (format "\nprocess %s" msg))))
709 ))
679 (if delete-buff 710 (if delete-buff
680 (kill-buffer Man-buffer) 711 (kill-buffer Man-buffer)
681 (if Man-fontify-manpage-flag 712 (if Man-fontify-manpage-flag
682 (Man-fontify-manpage) 713 (Man-fontify-manpage)
683 (Man-cleanup-manpage)) 714 (Man-cleanup-manpage))
684 (run-hooks 'Man-cooked-hook) 715 (run-hooks 'Man-cooked-hook)
685 (Man-mode) 716 (Man-mode)
686 (set-buffer-modified-p nil) 717 (set-buffer-modified-p nil)
687 ) 718 ))
688 ;; Restore case-fold-search before calling 719 ;; Restore case-fold-search before calling
689 ;; Man-notify-when-ready because it may switch buffers. 720 ;; Man-notify-when-ready because it may switch buffers.
690 721
691 (if (not delete-buff) 722 (if (not delete-buff)
692 (Man-notify-when-ready Man-buffer)) 723 (Man-notify-when-ready Man-buffer))