[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

dynamic completing of search path strings

From: Benjamin Rutt
Subject: dynamic completing of search path strings
Date: Sat, 02 Oct 2004 15:43:40 -0400
User-agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3.50 (gnu/linux)

This function helps when you are completing search path strings using
comint-dynamic-complete, e.g. in .bashrc:

export PATH=/usr/local/bi<--  cursor is here

Then you can do M-x comint-dynamic-complete RET and it will expand to 

export PATH=/usr/local/bin/

I use

(global-set-key (kbd "<S-tab>") 'comint-dynamic-complete)

to make it fewer keystrokes to complete filenames when I'm editing
files, e.g. ~/.bashrc.

I was thinking of suggesting to integrate this into comint.el in GNU
Emacs, but was worried it might be a little hackish.  So here it is.
Activation of it is below, and also a little hackish.

(defun comint-dynamic-complete-search-path-trailing-filename ()
  "Completes trailing filenames in search paths.

This method is convenient, for example, when point is after the
\"x\" in the statement

export PATH=$PATH:/usr/local/bi

which will expand to

export PATH=$PATH:/usr/local/bin/

when a directory /usr/local/bin exists."
  (let* ((m nil)
         (result nil)
         (deleted-char nil))
      (when (re-search-backward (concat "[=" path-separator "]")
                                (line-beginning-position) t)
        (setq m (point-marker))
        (setq deleted-char (buffer-substring (point) (1+ (point))))
        (delete-char 1)
        (insert ?\ )))
    (setq result (comint-dynamic-complete-filename))
      (when m
        (goto-char m)
        (delete-char 1)
        (insert deleted-char)))

;; to activate it globally (because each mode may set
;; comint-dynamic-complete-filename), I do:

(defadvice comint-dynamic-complete-filename
  (before comint-dynamic-complete-filename-include-pathstr activate)
  (add-to-list 'comint-dynamic-complete-functions
Benjamin Rutt

reply via email to

[Prev in Thread] Current Thread [Next in Thread]