comparison lisp/info.el @ 63065:58dcb71db77b

(Info-read-node-name-2): New function. (Info-read-node-name-1): Use that. Add a completion-base-size-function property.
author Richard M. Stallman <rms@gnu.org>
date Mon, 06 Jun 2005 12:47:51 +0000
parents 1fefd865fb18
children 0502430a647c 173dee4e2611
comparison
equal deleted inserted replaced
63064:7e053d892401 63065:58dcb71db77b
1377 (Info-find-node (if (equal filename "") nil filename) 1377 (Info-find-node (if (equal filename "") nil filename)
1378 (if (equal nodename "") "Top" nodename)))) 1378 (if (equal nodename "") "Top" nodename))))
1379 1379
1380 (defvar Info-read-node-completion-table) 1380 (defvar Info-read-node-completion-table)
1381 1381
1382 (defun Info-read-node-name-2 (string path-and-suffixes action)
1383 "Virtual completion table for file names input in Info node names.
1384 PATH-AND-SUFFIXES is a pair of lists, (DIRECTORIES . SUFFIXES)."
1385 (let* ((names nil)
1386 (suffixes (remove "" (cdr path-and-suffixes)))
1387 (suffix (concat (regexp-opt suffixes t) "\\'"))
1388 (string-dir (file-name-directory string))
1389 (dirs
1390 (if (file-name-absolute-p string)
1391 (list (file-name-directory string))
1392 (car path-and-suffixes))))
1393 (dolist (dir dirs)
1394 (unless dir
1395 (setq dir default-directory))
1396 (if string-dir (setq dir (expand-file-name string-dir dir)))
1397 (when (file-directory-p dir)
1398 (dolist (file (file-name-all-completions
1399 (file-name-nondirectory string) dir))
1400 ;; If the file name has no suffix or a standard suffix,
1401 ;; include it.
1402 (and (or (null (file-name-extension file))
1403 (string-match suffix file))
1404 ;; But exclude subfiles of split info files.
1405 (not (string-match "-[0-9]+\\'" file))
1406 ;; And exclude backup files.
1407 (not (string-match "~\\'" file))
1408 (push (if string-dir (concat string-dir file) file) names))
1409 ;; If the file name ends in a standard suffix,
1410 ;; add the unsuffixed name as a completion option.
1411 (when (string-match suffix file)
1412 (setq file (substring file 0 (match-beginning 0)))
1413 (push (if string-dir (concat string-dir file) file) names)))))
1414 (cond
1415 ((eq action t) (all-completions string names))
1416 ((null action) (try-completion string names))
1417 (t (test-completion string names)))))
1418
1382 ;; This function is used as the "completion table" while reading a node name. 1419 ;; This function is used as the "completion table" while reading a node name.
1383 ;; It does completion using the alist in Info-read-node-completion-table 1420 ;; It does completion using the alist in Info-read-node-completion-table
1384 ;; unless STRING starts with an open-paren. 1421 ;; unless STRING starts with an open-paren.
1385 (defun Info-read-node-name-1 (string predicate code) 1422 (defun Info-read-node-name-1 (string predicate code)
1386 (cond 1423 (cond
1387 ;; First complete embedded file names. 1424 ;; First complete embedded file names.
1388 ((string-match "\\`([^)]*\\'" string) 1425 ((string-match "\\`([^)]*\\'" string)
1389 (let ((file (substring string 1))) 1426 (let ((file (substring string 1)))
1390 (cond 1427 (cond
1391 ((eq code nil) 1428 ((eq code nil)
1392 (let ((comp (try-completion file 'locate-file-completion 1429 (let ((comp (try-completion file 'Info-read-node-name-2
1393 (cons Info-directory-list 1430 (cons Info-directory-list
1394 (mapcar 'car Info-suffix-list))))) 1431 (mapcar 'car Info-suffix-list)))))
1395 (cond 1432 (cond
1396 ((eq comp t) (concat string ")")) 1433 ((eq comp t) (concat string ")"))
1397 (comp (concat "(" comp))))) 1434 (comp (concat "(" comp)))))
1398 ((eq code t) (all-completions file 'locate-file-completion 1435 ((eq code t)
1399 (cons Info-directory-list 1436 (all-completions file 'Info-read-node-name-2
1400 (mapcar 'car Info-suffix-list)))) 1437 (cons Info-directory-list
1438 (mapcar 'car Info-suffix-list))))
1401 (t nil)))) 1439 (t nil))))
1402 ;; If a file name was given, then any node is fair game. 1440 ;; If a file name was given, then any node is fair game.
1403 ((string-match "\\`(" string) 1441 ((string-match "\\`(" string)
1404 (cond 1442 (cond
1405 ((eq code nil) string) 1443 ((eq code nil) string)
1410 (try-completion string Info-read-node-completion-table predicate)) 1448 (try-completion string Info-read-node-completion-table predicate))
1411 ((eq code t) 1449 ((eq code t)
1412 (all-completions string Info-read-node-completion-table predicate)) 1450 (all-completions string Info-read-node-completion-table predicate))
1413 (t 1451 (t
1414 (test-completion string Info-read-node-completion-table predicate)))) 1452 (test-completion string Info-read-node-completion-table predicate))))
1453
1454 ;; Arrange to highlight the proper letters in the completion list buffer.
1455 (put 'Info-read-node-name-1 'completion-base-size-function
1456 (lambda () 1))
1415 1457
1416 (defun Info-read-node-name (prompt &optional default) 1458 (defun Info-read-node-name (prompt &optional default)
1417 (let* ((completion-ignore-case t) 1459 (let* ((completion-ignore-case t)
1418 (Info-read-node-completion-table (Info-build-node-completions)) 1460 (Info-read-node-completion-table (Info-build-node-completions))
1419 (nodename (completing-read prompt 'Info-read-node-name-1 nil t))) 1461 (nodename (completing-read prompt 'Info-read-node-name-1 nil t)))