comparison lisp/dired-x.el @ 49485:7c879dba798f

(dired-filename-at-point): Fix last change and tidy up.
author Dave Love <fx@gnu.org>
date Mon, 27 Jan 2003 11:36:08 +0000
parents 720dd3042058
children 37645a051842
comparison
equal deleted inserted replaced
49484:4e26b69ee15d 49485:7c879dba798f
1559 (interactive (list (read-filename-at-point "Find file: "))) 1559 (interactive (list (read-filename-at-point "Find file: ")))
1560 (find-file-other-window (expand-file-name filename))) 1560 (find-file-other-window (expand-file-name filename)))
1561 1561
1562 ;;; Internal functions. 1562 ;;; Internal functions.
1563 1563
1564 ;; Fixme: This should probably be replaced with `thing-at-point', but 1564 ;; Fixme: This should probably use `thing-at-point'. -- fx
1565 ;; that needs checking for compatibility. -- fx
1566 (defun dired-filename-at-point () 1565 (defun dired-filename-at-point ()
1567 "Get the filename closest to point, but do not change position. 1566 "Get the filename closest to point, but do not change position.
1568 Has a preference for looking backward when not directly on a symbol. Not 1567 Has a preference for looking backward when not directly on a symbol. Not
1569 perfect - point must be in middle of or end of filename." 1568 perfect - point must be in middle of or end of filename."
1570 1569
1571 (let ((filename-chars "-.[:alnum:]_/:$+@") 1570 (let ((filename-chars "-.[:alnum:]_/:$+@")
1572 (bol (save-excursion (beginning-of-line) (point)))
1573 (eol (save-excursion (end-of-line) (point)))
1574 start end filename prefix) 1571 start end filename prefix)
1575 1572
1576 (save-excursion 1573 (save-excursion
1577 ;; First see if just past a filename. 1574 ;; First see if just past a filename.
1578 (if (not (eobp)) 1575 (if (not (eobp))
1583 (backward-char 1))))) 1580 (backward-char 1)))))
1584 1581
1585 (if (string-match (concat "[" filename-chars "]") 1582 (if (string-match (concat "[" filename-chars "]")
1586 (char-to-string (following-char))) 1583 (char-to-string (following-char)))
1587 (progn 1584 (progn
1588 (skip-chars-backward filename-chars) 1585 (if (re-search-backward (concat "[^" filename-chars "]") nil t)
1586 (forward-char)
1587 (goto-char (point-min)))
1589 (setq start (point)) 1588 (setq start (point))
1590 (setq prefix 1589 (setq prefix
1591 (and (string-match "^\\w+@" 1590 (and (string-match
1592 (buffer-substring start eol)) 1591 "^\\w+@"
1592 (buffer-substring start (line-beginning-position)))
1593 "/")) 1593 "/"))
1594 (goto-char start) 1594 (goto-char start)
1595 (if (string-match "[/~]" (char-to-string (preceding-char))) 1595 (if (string-match "[/~]" (char-to-string (preceding-char)))
1596 (setq start (1- start))) 1596 (setq start (1- start)))
1597 (skip-chars-forward filename-chars)) 1597 (re-search-forward (concat "\\=[" filename-chars "]*") nil t))
1598 1598
1599 (error "No file found around point!")) 1599 (error "No file found around point!"))
1600 1600
1601 ;; Return string. 1601 ;; Return string.
1602 (expand-file-name (concat prefix (buffer-substring start (point))))))) 1602 (expand-file-name (concat prefix (buffer-substring start (point)))))))