[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Preloading Command/Parameter Recall in .emacs?
From: |
Thien-Thi Nguyen |
Subject: |
Re: Preloading Command/Parameter Recall in .emacs? |
Date: |
28 Jul 2003 19:06:07 -0400 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 |
"Siegfried Heintze" <sieg_heintze@yahoo.com> writes:
> I'm particularly intersted in the find
> file command (C-x C-f).
i like to use
(setenv "e" "/home/ttn/build/GNU/emacs")
then the sequence is `C-x C-f $ e RET' to start dired there. below is
some reverse-substitution elisp you can use (for example) in the hook of
your favorite buffer listing facility, to both reduce clutter and remind
yourself of the association.
in any case, try `M-p' to recall previously-entered input.
thi
______________________________________________
;;; ID: buffer-substitute-file-env-vars.el,v 1.9 2000/06/01 23:39:49 ttn Rel
;;;
;;; Copyright (C) 1998-2000 Thien-Thi Nguyen
;;; This file is part of ttn's personal elisp library, released under GNU
;;; GPL with ABSOLUTELY NO WARRANTY. See the file COPYING for details.
;;; Description: In current buffer, substitute env vars that look like files.
;;; Commentary:
;; Rewritten for inclusion in Emacs (remove external dependency).
;;; Code:
;;;###autoload
(defun buffer-substitute-file-env-vars ()
(let (buffer-read-only
(ms-lose (memq system-type '(ms-dos windows-nt))))
(save-excursion
(mapcar (lambda (ev-pair)
;; In buffer, replace EV w/ backward mapping.
(goto-char (point-max))
(let ((var (car ev-pair))
(val (cdr ev-pair)))
(while (search-backward val (point-min) t)
(replace-match (concat "$" var)))))
;; FEV-PAIRS is a sorted canonicallized list, longest first.
(sort
(let (fev-pairs)
(mapcar (lambda (ev)
(let* ((x (string-match "=" ev))
(v (and x (substring ev (1+ x))))
(val (and
v
(not (string= v ""))
(if (eq ?~ (aref v 0))
(concat (getenv "HOME")
(substring v 1))
v))))
(when (and val (or (eq ?/ (aref val 0))
(and ms-lose
(string-match
"^[a-zA-Z]:/" val))))
(setq fev-pairs
(cons (cons (substring ev 0 x) val)
fev-pairs)))))
process-environment)
fev-pairs)
(lambda (a b)
(> (length (cdr a)) (length (cdr b))))))
;; Do HOME, then HOOD replacements.
;; HOOD is short for neighborhood, the parent dir of HOME.
(goto-char 1)
(while (re-search-forward "$HOME\\>" (point-max) t)
(replace-match "~"))
(let* ((hood (file-name-directory (getenv "HOME"))))
(unless (string= hood "/")
(goto-char (point-max))
(while (search-backward hood (point-min) t)
(replace-match "~")))))))
;;; buffer-substitute-file-env-vars.el,v1.9 ends here