diff options
| author | Stefan Monnier | 2003-02-11 21:00:58 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2003-02-11 21:00:58 +0000 |
| commit | da05debc31ad5f15454238ae806d6cd2c3064a4a (patch) | |
| tree | 03a96e9b92edb0e389bc6d10d812cac9c4a4227d | |
| parent | ae0fa1e0d3db2942ca60aa6949996a2fcb6252a2 (diff) | |
| download | emacs-da05debc31ad5f15454238ae806d6cd2c3064a4a.tar.gz emacs-da05debc31ad5f15454238ae806d6cd2c3064a4a.zip | |
(info-xref-check): Use line-beginning-position.
(info-xref-all-info-files): Cons a bit less.
(info-xref-check-buffer): Use push and replace-regexp-in-string.
(info-xref-output): Call insert only once.
(info-xref-whitespace): Remove.
| -rw-r--r-- | lisp/info-xref.el | 57 |
1 files changed, 16 insertions, 41 deletions
diff --git a/lisp/info-xref.el b/lisp/info-xref.el index 0327fe4337a..bc959cee8a7 100644 --- a/lisp/info-xref.el +++ b/lisp/info-xref.el | |||
| @@ -106,15 +106,12 @@ | |||
| 106 | (goto-char (point-min)) | 106 | (goto-char (point-min)) |
| 107 | (if (re-search-forward | 107 | (if (re-search-forward |
| 108 | "^@setfilename[ \t]+\\([^ \t\n]+\\)[ \t]*" | 108 | "^@setfilename[ \t]+\\([^ \t\n]+\\)[ \t]*" |
| 109 | (save-excursion (forward-line 100) (point)) t) | 109 | (line-beginning-position 100) t) |
| 110 | (expand-file-name (match-string 1))))))) | 110 | (expand-file-name (match-string 1))))))) |
| 111 | (prompt (if default-filename | 111 | (prompt (if default-filename |
| 112 | (format "Info file (%s): " default-filename) | 112 | (format "Info file (%s): " default-filename) |
| 113 | "Info file: "))) | 113 | "Info file: "))) |
| 114 | (read-file-name prompt | 114 | (read-file-name prompt nil default-filename t)))) |
| 115 | default-directory | ||
| 116 | default-filename | ||
| 117 | t)))) | ||
| 118 | (info-xref-check-list (list filename))) | 115 | (info-xref-check-list (list filename))) |
| 119 | 116 | ||
| 120 | ;;;###autoload | 117 | ;;;###autoload |
| @@ -139,15 +136,14 @@ relevant directories are considered, which might mean a lot of extraneous | |||
| 139 | things are returned if for instance a source code directory is in the path." | 136 | things are returned if for instance a source code directory is in the path." |
| 140 | 137 | ||
| 141 | (info-initialize) ;; establish Info-directory-list | 138 | (info-initialize) ;; establish Info-directory-list |
| 142 | (apply 'append | 139 | (apply 'nconc |
| 143 | (mapcar | 140 | (mapcar |
| 144 | (lambda (dir) | 141 | (lambda (dir) |
| 145 | (let ((result nil)) | 142 | (let ((result nil)) |
| 146 | (dolist (name (directory-files dir t)) | 143 | (dolist (name (directory-files dir t)) |
| 147 | (if (and (not (file-directory-p name)) | 144 | (unless (or (file-directory-p name) (info-xref-subfile-p name)) |
| 148 | (not (info-xref-subfile-p name))) | 145 | (push name result))) |
| 149 | (setq result (cons name result)))) | 146 | (nreverse result))) |
| 150 | (reverse result))) | ||
| 151 | (append Info-directory-list Info-additional-directory-list)))) | 147 | (append Info-directory-list Info-additional-directory-list)))) |
| 152 | 148 | ||
| 153 | (defun info-xref-subfile-p (filename) | 149 | (defun info-xref-subfile-p (filename) |
| @@ -211,15 +207,16 @@ This should be the raw file contents, not `Info-mode'." | |||
| 211 | "\\*[Nn]ote[ \n\t]+[^:]*:[ \n\t]+\\(\\(([^)]+)\\)[^.,]+\\)[.,]" | 207 | "\\*[Nn]ote[ \n\t]+[^:]*:[ \n\t]+\\(\\(([^)]+)\\)[^.,]+\\)[.,]" |
| 212 | nil t) | 208 | nil t) |
| 213 | (let* ((file (match-string 2)) | 209 | (let* ((file (match-string 2)) |
| 214 | (node (info-xref-whitespace (match-string 1)))) | 210 | (node ;; Canonicalize spaces: we could use "[\t\n ]+" but |
| 211 | ;; we try to avoid uselessly replacing " " with " ". | ||
| 212 | (replace-regexp-in-string "[\t\n][\t\n ]*\\| [\t\n ]+" " " | ||
| 213 | (match-string 1) t t))) | ||
| 215 | ;; see if the file exists, if we haven't tried it before | 214 | ;; see if the file exists, if we haven't tried it before |
| 216 | (unless (assoc file info-xref-xfile-alist) | 215 | (unless (assoc file info-xref-xfile-alist) |
| 217 | (let ((found (info-xref-goto-node-p file))) | 216 | (let ((found (info-xref-goto-node-p file))) |
| 218 | (setq info-xref-xfile-alist (cons (cons file found) | 217 | (push (cons file found) info-xref-xfile-alist) |
| 219 | info-xref-xfile-alist)) | 218 | (unless found |
| 220 | (if (not found) | 219 | (info-xref-output (format "Not available to check: %s\n" file))))) |
| 221 | (info-xref-output | ||
| 222 | (format "Not available to check: %s\n" file))))) | ||
| 223 | ;; if the file exists, try the node, if we haven't before | 220 | ;; if the file exists, try the node, if we haven't before |
| 224 | (when (cdr (assoc file info-xref-xfile-alist)) | 221 | (when (cdr (assoc file info-xref-xfile-alist)) |
| 225 | (unless (assoc node info-xref-xfile-alist) | 222 | (unless (assoc node info-xref-xfile-alist) |
| @@ -231,9 +228,8 @@ This should be the raw file contents, not `Info-mode'." | |||
| 231 | (defun info-xref-output (str) | 228 | (defun info-xref-output (str) |
| 232 | "Emit STR as an info-xref result message." | 229 | "Emit STR as an info-xref result message." |
| 233 | (with-current-buffer info-xref-results-buffer | 230 | (with-current-buffer info-xref-results-buffer |
| 234 | (insert info-xref-filename-heading) | 231 | (insert info-xref-filename-heading str) |
| 235 | (setq info-xref-filename-heading "") | 232 | (setq info-xref-filename-heading ""))) |
| 236 | (insert str))) | ||
| 237 | 233 | ||
| 238 | ;; When asking Info-goto-node to fork, *info* needs to be the current | 234 | ;; When asking Info-goto-node to fork, *info* needs to be the current |
| 239 | ;; buffer, otherwise it seems to clone the current buffer but then do the | 235 | ;; buffer, otherwise it seems to clone the current buffer but then do the |
| @@ -247,7 +243,7 @@ This should be the raw file contents, not `Info-mode'." | |||
| 247 | ;; this difference by checking before killing. | 243 | ;; this difference by checking before killing. |
| 248 | ;; | 244 | ;; |
| 249 | (defun info-xref-goto-node-p (node) | 245 | (defun info-xref-goto-node-p (node) |
| 250 | "Return t if it's possible to goto the given NODE." | 246 | "Return t if it's possible to go to the given NODE." |
| 251 | (let ((oldbuf (current-buffer))) | 247 | (let ((oldbuf (current-buffer))) |
| 252 | (save-excursion | 248 | (save-excursion |
| 253 | (save-window-excursion | 249 | (save-window-excursion |
| @@ -263,27 +259,6 @@ This should be the raw file contents, not `Info-mode'." | |||
| 263 | (unless (equal (current-buffer) oldbuf) | 259 | (unless (equal (current-buffer) oldbuf) |
| 264 | (kill-buffer (current-buffer)))))))) | 260 | (kill-buffer (current-buffer)))))))) |
| 265 | 261 | ||
| 266 | ;; Can this be done better? | ||
| 267 | (defun info-xref-whitespace (str) | ||
| 268 | "In STR, convert tabs and newlines to spaces, collapse repeated spaces." | ||
| 269 | (setq str (copy-sequence str)) | ||
| 270 | (dotimes (i (length str)) | ||
| 271 | (let ((c (elt str i))) | ||
| 272 | (if (or (= c ?\n) | ||
| 273 | (= c ?\t)) | ||
| 274 | (aset str i ? )))) | ||
| 275 | (let ((dst 0) | ||
| 276 | (prev -1)) | ||
| 277 | (dotimes (i (length str)) | ||
| 278 | (let ((c (elt str i))) | ||
| 279 | (unless (and (= c ? ) | ||
| 280 | (= prev ? )) | ||
| 281 | (aset str dst c) | ||
| 282 | (setq dst (1+ dst))) | ||
| 283 | (setq prev c))) | ||
| 284 | (setq str (substring str 0 dst))) | ||
| 285 | str) | ||
| 286 | |||
| 287 | (provide 'info-xref) | 262 | (provide 'info-xref) |
| 288 | 263 | ||
| 289 | ;;; info-xref.el ends here | 264 | ;;; info-xref.el ends here |