help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: How do I make `man' run some code after the manpage is fully rendere


From: Eduardo Ochs
Subject: Re: How do I make `man' run some code after the manpage is fully rendered?
Date: Sat, 2 Jan 2021 06:04:37 -0300

Perfect, thanks!!!

The code below - with (advice-add 'Man-bgproc-sentinel ...) - works in
at least Emacs25.2, Emacs26, and Emacs27 - I got a segfault trying to
compile Emacs25.1 here.

The code is just 32 lines long, so I thought that it would be worth
sharing it with the list.

  Cheers! =)
    Eduardo Ochs
    http://angg.twu.net/#eev

Here it goes:


  (defvar ee-find-man-flag          nil "See `find-man'.")
  (defvar ee-find-man-buffer        nil "See `find-man'.")
  (defvar ee-find-man-pos-spec-list nil "See `find-man'.")

  (defun find-man (manpage &rest pos-spec-list)
    "Hyperlink to a manpage."
    (interactive (list (ee-manpagename-ask)))
    (setq manpage (Man-translate-references manpage))
    ;;
    ;; Set the variables used by `ee-find-man-goto-pos-spec'.
    (setq ee-find-man-flag t)
    (setq ee-find-man-buffer (concat "*Man " manpage "*"))
    (setq ee-find-man-pos-spec-list pos-spec-list)
    ;;
    ;; See: (find-evardescr 'Man-notify-method "pushy" "current window")
    (let ((Man-notify-method 'pushy))
      ;;
      ;; This call to `man' will run `ee-find-man-goto-pos-spec' after
      ;; the manpage is rendered - because of the `advice-add' below.
      ;; This is a dirty trick!... see:
      ;; https://lists.gnu.org/archive/html/help-gnu-emacs/2020-12/msg01100.html
      ;; https://lists.gnu.org/archive/html/help-gnu-emacs/2020-12/msg01102.html
      (man manpage)))

  (defun ee-find-man-goto-pos-spec (&rest rest)
    "An internal function used by `find-man'."
    (when ee-find-man-flag
      (setq ee-find-man-flag nil)
      (with-current-buffer ee-find-man-buffer
        (apply 'ee-goto-position ee-find-man-pos-spec-list))))

  (advice-add 'Man-bgproc-sentinel :after 'ee-find-man-goto-pos-spec)


On Tue, 29 Dec 2020 at 03:19, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>
> If you need to adjust the content of the page, then you can try using
> the `Man-cooked-hook`.  But if you need to move to a particular position
> that won't help because man moves to page 1 after running this hook.
> I think withthe current man.el code you'll need an advice on
> `Man-bgproc-sentinel`.
>
>         Stefan



reply via email to

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