;; info.el --- info package for Emacs
-;; Copyright (C) 1985-1986, 1992-2013 Free Software Foundation, Inc.
+;; Copyright (C) 1985-1986, 1992-2014 Free Software Foundation, Inc.
-;; Maintainer: FSF
+;; Maintainer: emacs-devel@gnu.org
;; Keywords: help
;; This file is part of GNU Emacs.
(defun info-setup (file-or-node buffer)
"Display Info node FILE-OR-NODE in BUFFER."
- (if (and buffer (not (eq major-mode 'Info-mode)))
+ (if (and buffer (not (derived-mode-p 'Info-mode)))
(Info-mode))
(if file-or-node
;; If argument already contains parentheses, don't add another set
(setq filename found)
(if noerror
(setq filename nil)
- (error "Info file %s does not exist" filename)))
+ ;; If there is no previous Info file, go to the directory.
+ (unless Info-current-file
+ (Info-directory))
+ (user-error "Info file %s does not exist" filename)))
filename))))
(defun Info-find-node (filename nodename &optional no-going-back strict-case)
(info-initialize)
(setq filename (Info-find-file filename))
;; Go into Info buffer.
- (or (eq major-mode 'Info-mode) (switch-to-buffer "*info*"))
+ (or (derived-mode-p 'Info-mode) (switch-to-buffer "*info*"))
;; Record the node we are leaving, if we were in one.
(and (not no-going-back)
Info-current-file
"Go to an Info node FILENAME and NODENAME, re-reading disk contents.
When *info* is already displaying FILENAME and NODENAME, the window position
is preserved, if possible."
- (or (eq major-mode 'Info-mode) (switch-to-buffer "*info*"))
+ (or (derived-mode-p 'Info-mode) (switch-to-buffer "*info*"))
(let ((old-filename Info-current-file)
(old-nodename Info-current-node)
(window-selected (eq (selected-window) (get-buffer-window)))
(defun Info-find-node-2 (filename nodename &optional no-going-back strict-case)
(buffer-disable-undo (current-buffer))
- (or (eq major-mode 'Info-mode)
+ (or (derived-mode-p 'Info-mode)
(Info-mode))
(widen)
(setq Info-current-node nil)
(Info-find-index-name Info-point-loc)
(setq Info-point-loc nil))))))
;; If we did not finish finding the specified node,
- ;; go back to the previous one.
- (or Info-current-node no-going-back (null Info-history)
- (let ((hist (car Info-history)))
- (setq Info-history (cdr Info-history))
- (Info-find-node (nth 0 hist) (nth 1 hist) t)
- (goto-char (nth 2 hist))))))
+ ;; go back to the previous one or to the Top node.
+ (unless (or Info-current-node no-going-back)
+ (if Info-history
+ (let ((hist (car Info-history)))
+ (setq Info-history (cdr Info-history))
+ (Info-find-node (nth 0 hist) (nth 1 hist) t)
+ (goto-char (nth 2 hist)))
+ (Info-find-node Info-current-file "Top" t)))))
;; Cache the contents of the (virtual) dir file, once we have merged
;; it for the first time, so we can save time subsequently.
""))
(image (if (file-exists-p image-file)
(create-image image-file)
- "[broken image]")))
+ (or (cdr (assoc-string "text" parameter-alist))
+ (and src (concat "[broken image:" src "]"))
+ "[broken image]"))))
(if (not (get-text-property start 'display))
(add-text-properties
- start (point) `(display ,image rear-nonsticky (display)))))
+ start (point)
+ `(display ,image rear-nonsticky (display)
+ help-echo ,(cdr (assoc-string "alt" parameter-alist))))))
;; text-only display, show alternative text if provided, or
;; otherwise a clue that there's meant to be a picture
(delete-region start (point))
(insert (or (cdr (assoc-string "text" parameter-alist))
(cdr (assoc-string "alt" parameter-alist))
- (and src
- (concat "[image:" src "]"))
+ (and src (concat "[image:" src "]"))
"[image]"))))))
(set-buffer-modified-p nil)))
(defvar Info-search-case-fold nil
"The value of `case-fold-search' from previous `Info-search' command.")
+(defun Info--search-loop (regexp bound backward)
+ (when backward
+ ;; Hide Info file header for backward search.
+ (narrow-to-region (save-excursion
+ (goto-char (point-min))
+ (search-forward "\n\^_")
+ (1- (point)))
+ (point-max)))
+ (let ((give-up nil)
+ (found nil)
+ (beg-found nil))
+ (while (not (or give-up
+ (and found
+ (funcall isearch-filter-predicate
+ beg-found found))))
+ (let ((search-spaces-regexp Info-search-whitespace-regexp))
+ (if (funcall
+ (if backward #'re-search-backward #'re-search-forward)
+ regexp bound t)
+ (setq found (point) beg-found (if backward (match-end 0)
+ (match-beginning 0)))
+ (setq give-up t found nil))))
+ found))
+
(defun Info-search (regexp &optional bound _noerror _count direction)
"Search for REGEXP, starting from point, and select node it's found in.
If DIRECTION is `backward', search in the reverse direction."
(when (equal regexp "")
(setq regexp (car Info-search-history)))
(when regexp
- (let (found beg-found give-up
- (backward (eq direction 'backward))
- (onode Info-current-node)
- (ofile Info-current-file)
- (opoint (point))
- (opoint-min (point-min))
- (opoint-max (point-max))
- (ostart (window-start))
- (osubfile Info-current-subfile))
- (setq Info-search-case-fold case-fold-search)
- (save-excursion
- (save-restriction
- (widen)
- (when backward
- ;; Hide Info file header for backward search
- (narrow-to-region (save-excursion
- (goto-char (point-min))
- (search-forward "\n\^_")
- (1- (point)))
- (point-max)))
- (while (and (not give-up)
- (or (null found)
- (not (run-hook-with-args-until-failure
- 'isearch-filter-predicates beg-found found))))
- (let ((search-spaces-regexp Info-search-whitespace-regexp))
- (if (if backward
- (re-search-backward regexp bound t)
- (re-search-forward regexp bound t))
- (setq found (point) beg-found (if backward (match-end 0)
- (match-beginning 0)))
- (setq give-up t))))))
-
- (when (and isearch-mode Info-isearch-search
- (not Info-isearch-initial-node)
- (not bound)
- (or give-up (and found (not (and (> found opoint-min)
- (< found opoint-max))))))
+ (setq Info-search-case-fold case-fold-search)
+ (let* ((backward (eq direction 'backward))
+ (onode Info-current-node)
+ (ofile Info-current-file)
+ (opoint (point))
+ (opoint-min (point-min))
+ (opoint-max (point-max))
+ (ostart (window-start))
+ (osubfile Info-current-subfile)
+ (found
+ (save-excursion
+ (save-restriction
+ (widen)
+ (Info--search-loop regexp bound backward)))))
+
+ (unless (or (not isearch-mode) (not Info-isearch-search)
+ Info-isearch-initial-node
+ bound
+ (and found (> found opoint-min) (< found opoint-max)))
(signal 'search-failed (list regexp "end of node")))
;; If no subfiles, give error now.
- (if give-up
- (if (null Info-current-subfile)
- (if isearch-mode
- (signal 'search-failed (list regexp "end of manual"))
- (let ((search-spaces-regexp Info-search-whitespace-regexp))
- (if backward
- (re-search-backward regexp)
- (re-search-forward regexp))))
- (setq found nil)))
+ (unless (or found Info-current-subfile)
+ (if isearch-mode
+ (signal 'search-failed (list regexp "end of manual"))
+ (let ((search-spaces-regexp Info-search-whitespace-regexp))
+ (if backward
+ (re-search-backward regexp)
+ (re-search-forward regexp)))))
(if (and bound (not found))
(signal 'search-failed (list regexp)))
(while list
(message "Searching subfile %s..." (cdr (car list)))
(Info-read-subfile (car (car list)))
- (when backward
- ;; Hide Info file header for backward search
- (narrow-to-region (save-excursion
- (goto-char (point-min))
- (search-forward "\n\^_")
- (1- (point)))
- (point-max))
- (goto-char (point-max)))
+ (when backward (goto-char (point-max)))
(setq list (cdr list))
- (setq give-up nil found nil)
- (while (and (not give-up)
- (or (null found)
- (not (run-hook-with-args-until-failure
- 'isearch-filter-predicates beg-found found))))
- (let ((search-spaces-regexp Info-search-whitespace-regexp))
- (if (if backward
- (re-search-backward regexp nil t)
- (re-search-forward regexp nil t))
- (setq found (point) beg-found (if backward (match-end 0)
- (match-beginning 0)))
- (setq give-up t))))
- (if give-up
- (setq found nil))
+ (setq found (Info--search-loop regexp nil backward))
(if found
(setq list nil)))
(if found
(interactive)
;; In case another window is currently selected
(save-window-excursion
- (or (eq major-mode 'Info-mode) (switch-to-buffer "*info*"))
+ (or (derived-mode-p 'Info-mode) (switch-to-buffer "*info*"))
(Info-goto-node (Info-extract-pointer "next"))))
(defun Info-prev ()
(interactive)
;; In case another window is currently selected
(save-window-excursion
- (or (eq major-mode 'Info-mode) (switch-to-buffer "*info*"))
+ (or (derived-mode-p 'Info-mode) (switch-to-buffer "*info*"))
(Info-goto-node (Info-extract-pointer "prev[ious]*" "previous"))))
(defun Info-up (&optional same-file)
(interactive)
;; In case another window is currently selected
(save-window-excursion
- (or (eq major-mode 'Info-mode) (switch-to-buffer "*info*"))
+ (or (derived-mode-p 'Info-mode) (switch-to-buffer "*info*"))
(let ((old-node Info-current-node)
(old-file Info-current-file)
(node (Info-extract-pointer "up")) p)
hits desc)
(dolist (keyword keywords)
(push (copy-tree (gethash keyword finder-keywords-hash)) hits))
- (setq hits (delete-dups (apply 'append hits)))
+ (setq hits (delete-dups (apply 'append hits))
+ ;; Not a meaningful package.
+ hits (delete 'emacs hits))
(dolist (package hits)
(setq desc (cdr-safe (assq package package--builtins)))
(when (vectorp desc)
(insert "*****************\n\n")
(insert
"Commentary section of the package `" nodename "':\n\n")
+ ;; FIXME this assumes that a file named package.el exists,
+ ;; which is not always true. E.g. for the nxml package,
+ ;; there is no "nxml.el" (it's nxml-mode.el).
(let ((str (lm-commentary (find-library-name nodename))))
(if (null str)
(insert "Can't find any Commentary section\n\n")
(define-key map "f" 'Info-follow-reference)
(define-key map "g" 'Info-goto-node)
(define-key map "h" 'Info-help)
+ ;; This is for compatibility with standalone info (>~ version 5.2).
+ ;; Though for some time, standalone info had H and h reversed.
+ ;; See <http://debbugs.gnu.org/16455>.
+ (define-key map "H" 'describe-mode)
(define-key map "i" 'Info-index)
(define-key map "I" 'Info-virtual-index)
(define-key map "l" 'Info-history-back)
(defun Info-menu-update ()
"Update the Info menu for the current node."
(condition-case nil
- (if (or (not (eq major-mode 'Info-mode))
+ (if (or (not (derived-mode-p 'Info-mode))
(equal (list Info-current-file Info-current-node)
Info-menu-last-node))
()
'Info-isearch-wrap)
(set (make-local-variable 'isearch-push-state-function)
'Info-isearch-push-state)
- (set (make-local-variable 'isearch-filter-predicates)
- '(Info-isearch-filter))
+ (set (make-local-variable 'isearch-filter-predicate) #'Info-isearch-filter)
(set (make-local-variable 'revert-buffer-function)
'Info-revert-buffer-function)
(Info-set-mode-line)
;; When an Info buffer is killed, make sure the associated tags buffer
;; is killed too.
(defun Info-kill-buffer ()
- (and (eq major-mode 'Info-mode)
+ (and (derived-mode-p 'Info-mode)
Info-tag-table-buffer
(kill-buffer Info-tag-table-buffer)))
(copy-marker (marker-position m)))
(make-marker))))))
-(defvar Info-edit-map (let ((map (make-sparse-keymap)))
- (set-keymap-parent map text-mode-map)
- (define-key map "\C-c\C-c" 'Info-cease-edit)
- map)
+(define-obsolete-variable-alias 'Info-edit-map 'Info-edit-mode-map "24.1")
+(defvar Info-edit-mode-map (let ((map (make-sparse-keymap)))
+ (set-keymap-parent map text-mode-map)
+ (define-key map "\C-c\C-c" 'Info-cease-edit)
+ map)
"Local keymap used within `e' command of Info.")
(make-obsolete-variable 'Info-edit-map
;; Info-edit mode is suitable only for specially formatted data.
(put 'Info-edit-mode 'mode-class 'special)
-(defun Info-edit-mode ()
+(define-derived-mode Info-edit-mode text-mode "Info Edit"
"Major mode for editing the contents of an Info node.
Like text mode with the addition of `Info-cease-edit'
which returns to Info mode for browsing.
\\{Info-edit-map}"
- (use-local-map Info-edit-map)
- (setq major-mode 'Info-edit-mode)
- (setq mode-name "Info Edit")
- (kill-local-variable 'mode-line-buffer-identification)
(setq buffer-read-only nil)
(force-mode-line-update)
- (buffer-enable-undo (current-buffer))
- (run-mode-hooks 'Info-edit-mode-hook))
+ (buffer-enable-undo (current-buffer)))
(make-obsolete 'Info-edit-mode
"editing Info nodes by hand is not recommended." "24.4")
(and (buffer-modified-p)
(y-or-n-p "Save the file? ")
(save-buffer))
- (use-local-map Info-mode-map)
- (setq major-mode 'Info-mode)
- (setq mode-name "Info")
- (Info-set-mode-line)
- (setq buffer-read-only t)
+ (Info-mode)
(force-mode-line-update)
(and (marker-position Info-tag-table-marker)
(buffer-modified-p)
;; Get Info running, and pop to it in another window.
(save-window-excursion
(info))
- (or (eq major-mode 'Info-mode) (pop-to-buffer "*info*"))
+ (or (derived-mode-p 'Info-mode) (pop-to-buffer "*info*"))
;; Bind Info-history to nil, to prevent the last Index node
;; visited by Info-find-emacs-command-nodes from being
;; pushed onto the history.
NODESPEC is a string of the form: (file)node."
;; Set up a buffer we can use to fake-out Info.
(with-current-buffer (get-buffer-create " *info-browse-tmp*")
- (if (not (equal major-mode 'Info-mode))
+ (if (not (derived-mode-p 'Info-mode))
(Info-mode))
;; Get the node into this buffer
(if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec))