3

I can view man pages using info in the terminal:

info pthread_create

However, it is not possible with info in Emacs, even with info-apropos or info-menu.

Amumu
  • 17,924
  • 31
  • 84
  • 131
  • 3
    `M-x man` provides access to manual pages. – ben rudgers Jan 02 '14 at 04:57
  • So there's no way to use `Info` for man pages in Emacs, so I don't have to manully switch back to `man` command when there's no such Info document exists? – Amumu Jan 02 '14 at 04:59
  • 2
    A little googliness turned up this: http://homepage1.nifty.com/bmonkey/emacs/elisp/iman.el - indirectly from emacswiki. It sounds like it might do what you want - if it doesn't there's probably something else that does because it is unlikely that you are the first person to experience what you are experiencing. – ben rudgers Jan 02 '14 at 05:03
  • 2
    @benrudgers If this solves the problem please write it as answer so that Amunmu can accept it else the question remains in the list of open problems. – Tobias Jan 02 '14 at 06:22
  • @benrudgers Ok I'm using `iman` and it does what I expected. You should add your answer. Regardless, I still want `info` to be able fall back to `man` when it needs to, so I don't have to rely on 3rd party package for this feature. – Amumu Jan 02 '14 at 08:38
  • @Tobias I did not use it as an answer because I could not verify that it works. If there are any man pages on the computer I use for Emacs, I wouldn't know it - man pages are not a paradigm of its operating system. – ben rudgers Jan 02 '14 at 15:30
  • @Amumu The standard approach of Emacs is such that most functionality is added by third parties - it's just that some of the more common ones get included as part of standard Emacs packages. It's a practice facilitated by Lisp where the difference between built-in code and extensions is not as meaningful as in other languages. – ben rudgers Jan 02 '14 at 15:36

3 Answers3

4

EDIT: It seems that fall-backs are not in the concept of Info-mode.

There follows a work-around applying advice. It does not work perfect but around the missing feature ;-).

It defines a fall-back for Info-goto-node (in Info-mode bound to g) and for Info-menu (in Info-mode bound to m). Furthermore, it adds manual-apropos to info-apropos.

(require 'woman)

(defun Info-man-completion (_caller _info string predicate action)
  "Add man entries to info completion."
  ;; prepare woman:
  (unless (and woman-expanded-directory-path woman-topic-all-completions)
    (setq woman-expanded-directory-path
      (woman-expand-directory-path woman-manpath woman-path)
      woman-topic-all-completions
      (woman-topic-all-completions woman-expanded-directory-path)))
  ;; do completions:
  (cond
   ((null action) ;; try-completion
    ;; shortest wins
    (let ((_man (try-completion string woman-topic-all-completions)))
      (cond
       ((eq _info t)
    t)
       ((eq _man t)
    t)
       ((and (stringp _info) (stringp _man))
    (if (> (length _info) (length _man))
        _man
      _info))
       ((stringp _info)
    _info)
       (t _man)
       )))
   ((eq action t) ;; all-completions
    (let ((_man (all-completions string woman-topic-all-completions)))
      (append _info _man)
      ))
   ((eq action 'lambda) ;; test-completion
    (try-completion string _caller))
   ((eq action 'metadata) ;; state of current completion
    '(metadata) ;; no specification
    )))

;; args: string predicate code
(defadvice Info-read-node-name-1 (around man activate)
  "Add man entries to info completion."
  (setq ad-return-value (apply 'Info-man-completion 'Info-read-node-name-1 ad-do-it (ad-get-args 0))))

;;
(defadvice Info-complete-menu-item (around man activate)
  "Add man entries to info completion."
  (setq ad-return-value (apply 'Info-man-completion 'Info-complete-menu-item ad-do-it (ad-get-args 0))))

(defadvice Info-goto-node (around man activate)
  "If no info node is found for string lookup and show man entry."
  (condition-case err
      ad-do-it
    (user-error
     (let ((err-str (car-safe (cdr err))))
       (if (and (stringp err-str)
        (string-match "No such node or anchor:" err-str))
         (man (ad-get-arg 0))
     (signal 'user-error err-str)
     )))))

(defadvice Info-menu (around man activate)
  "If no info menu entry is found for string lookup and show man entry."
  (condition-case err
      ad-do-it
    (user-error
     (let ((err-str (car-safe (cdr err))))
       (if (and (stringp err-str)
        (string-match "No such item in menu" err-str))
         (man (ad-get-arg 0))
     (signal 'user-error err-str)
     )))))

(defadvice Info-apropos-find-node (after man activate)
  "Add man appropos to info appropos."
  (let (item)
    (goto-char (point-max))
    (let ((inhibit-read-only t))
      (insert "\nMatches found by man-apropos\n\n")
      (let ((beg (point))
        (nodeinfo (assoc nodename Info-apropos-nodes)))
        (if nodeinfo
        (let ((search-string (nth 1 nodeinfo)))
          (call-process "apropos" nil t t search-string)
          (goto-char beg)
          (while (re-search-forward "^\\(\\(?:[[:alnum:]]\\|\\s_\\)+\\)\\(?:[[:blank:]]+\\[\\]\\)?\\([[:blank:]]+([[:alnum:]]+)\\)[[:blank:]]+-[[:blank:]]+\\(.*\\)$" nil t)
            (replace-match (replace-regexp-in-string "\\\\" "\\\\\\\\" (format "* %-38s.%s"
                                               (format "%s:" (match-string 1))
                                               (concat (match-string 1) (match-string 2))
                                               (match-string 3))))))
          (man nodename)
          )))))

Info gives an error that the node is not available. Thereafter, the manual page is shown if there is one.

Tobias
  • 5,038
  • 1
  • 18
  • 39
  • While this works fine, it still does not have completions for entries not in Info. Could you also make it query man entries for the list of completion? Then it would be perfect. – Amumu Jan 03 '14 at 13:48
  • Nice! You should create a package out of this. – Amumu Jan 07 '14 at 03:37
1

[Edited]

EmacsWiki says that iman:

Opens either an info format manual with InfoMode or a man page with ManMode.

It links to the author's website: http://homepage1.nifty.com/bmonkey/emacs/elisp/iman.el

ben rudgers
  • 3,647
  • 2
  • 20
  • 32
  • 2
    I don't think this is what the OP was asking. On the command line, if you do `info something` and there is no `info` page found for `something`, the system falls back to looking for a `man` page for `something` and displays it in `info` using `*manpages*` as the `info` node. This fallback isn't happening in Emacs. – ChrisGPT was on strike Jan 02 '14 at 04:30
  • So basically `M-x man`? http://www.gnu.org/software/emacs/manual/html_node/emacs/Man-Page.html – ben rudgers Jan 02 '14 at 04:53
  • @Chris I have revised the answer to reflect the solution to the OP's problem. Thanks for setting me straight. – ben rudgers Jan 02 '14 at 15:41
0

Found M-x woman MANPAGE RET to most convenient way to call manpages from inside Emacs.

Andreas Röhler
  • 4,804
  • 14
  • 18