Path: utzoo!utgpu!water!watmath!clyde!rutgers!topaz.rutgers.edu!gaynor From: gaynor@topaz.rutgers.edu (Silver) Newsgroups: comp.emacs Subject: Re: alist help for an elisp beginner Message-ID: <18055@topaz.rutgers.edu> Date: 14 Feb 88 01:13:01 GMT References: <276@ho7cad.ATT.COM> Organization: Rutgers Univ., New Brunswick, N.J. Lines: 165 This stuff is looking *real* familiar. Did you grab it off the net about, oh, say, 18 months ago? I posted stuff then that massively hacked the buffer identification displayed in the prompt. I'm including the pertinent portions of my own .emacs.el and .emacs that I think are rather useful. This is my .emacs. Since I screw up my emacs environment mightily, I want it in compiled form (I never timed things, but I assume that it will load and run faster). This .emacs ensures that it always stays compiled, by `make'ing it when necessary. ------------------------------- .emacs ------------------------------- ;; Byte-compile ~/.emacs from ~/.emacs.el ;; if necessary, then load ~/.emacs.elc. (let ((el (expand-file-name "~/.emacs.el")) (elc (expand-file-name "~/.emacs.elc"))) (if (file-newer-than-file-p el elc) (progn (message "%s is not up to date, byte-compiling %s..." el elc) (sit-for 1) (byte-compile-file el))) (load-file elc)) ---------------------------------------------------------------------- ----------------------- portions of .emacs.el ------------------------ (defvar hostname (substring (system-name) 0 (string-match "\\." (system-name))) "The name of the host sans domains, as per (system-name).") (defvar username (user-login-name) "The username, as per (user-login-name).") (setq find-file-hooks '(abbreviate-mode-line-buffer-identification)) (setq write-file-hooks '(update-mode-line-buffer-identification)) ;;;;;;;;;; mode-line-format ;;;;;;;;;; ;; Make mode-line-buffer-identification local to every buffer. A ;; find-file-hook abbreviates the buffer-file-name to something a ;; little easier to read. ;; ;; file name, originally = buffer-file-name ;; abbreviations = file-name-abbreviation-alist ;; means of abbreviation = string-replace-regexp-alist ;; find-file hook = abbreviate-mode-line-buffer-identification ;; Customize mode-line-format and it's constituents. Remember, ;; mode-line-buffer-identification MUST be used to identify the ;; buffer. mode-line-modified is retained because it is in emacs's ;; default default-mode-line-format, and emacs may do some clever ;; tricks with it. (setq emacs-identification (list hostname)) (make-variable-buffer-local 'mode-line-buffer-identification) (make-variable-buffer-local 'mode-line-modified) (setq-default mode-line-buffer-identification '("%17b")) (setq-default mode-line-format '("" mode-line-modified emacs-identification ": " mode-line-buffer-identification " " global-mode-string " %[(" mode-name "%n" mode-line-process minor-mode-alist ")%]----" (-3 . "%p") "-%-")) (defvar file-name-abbreviations nil "Alist of embedded filename patterns vs corresponding abbreviations. Each element is of the form (regexp . to-string).") ;; [^/][ug/|fac/|grad/|staff/]u/ -> ~ ;; ~$USER -> ~ ;; ~/src/ -> ;; ^.*/cs431/project/documentation/requirements -> reqs (setq file-name-abbreviations (list '("\\(^/\\|\\)\\(ug/\\|grad/\\|fac/\\|staff/\\|\\)u[1-9][0-9]*/" . "~") (cons (concat "~" (getenv "USER")) "~") '("~/src/" . "") '("^.*/cs431/project/documentation/requirements" . "reqs"))) (defun abbreviate-mode-line-buffer-identification () "Abbreviates mode-line-buffer-identification locally, as per string-replace-regexps and file-name-abbreviations." (setq mode-line-buffer-identification (list (string-replace-regexps buffer-file-name file-name-abbreviations)))) (defun update-mode-line-buffer-identification () "Abbreviates mode-line-buffer-identification locally, as per abbreviate-mode-line-buffer-identification, but only if write-file was the most recent command. If so, then buffer-file-name is probably being changed and needs to be updated." (if (equal (car (car command-history)) 'write-file) (abbreviate-mode-line-buffer-identification))) ;; string-replace-regexp and string-replace-regexps are also defined ;; in my tools, where they belong. This file is not always loaded, ;; though. (defun string-replace-regexp (s re to-s) "Return STRING after replacing all successive instances of REGEXP with TO-STRING. See replace-regexp." (save-excursion (set-buffer (get-buffer-create " *temporary*")) ;; Note the space here ---------^, making the buffer `invisible'. (erase-buffer) (insert s) (goto-char (point-min)) (replace-regexp re to-s) (buffer-string))) (defun string-replace-regexps (s al) "Return STRING after replacing all successive instances of regexp cars of ALIST with to-string cdrs." (save-excursion (set-buffer (get-buffer-create " *temporary*")) (erase-buffer) (insert s) (mapcar '(lambda (el) (goto-char (point-min)) (replace-regexp (car el) (cdr el))) al) (buffer-string))) ---------------------------------------------------------------------- As to your problem that you posted, > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; > ;; I'd like this, but I get an error on argument type of > ;; "char-or-string-p" when it runs. Any help? > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; > (defvar file-name-abbreviation-alist > '( > ((format "^%s" (getenv "HOME")) . "~") > ((format "^%s" (getenv "TOOLS")) . "") ^^^^^^^^^^^^^^^^ > ) The arrowed portion is probably what's causing you problems. If the envariable TOOLS was not set at the time that emacs was invoked, then `getenv'ing it should return nil, which is neither a char nor a string. NG. Either mention the path explicitly, or setenv TOOLS before starting emacs. ___ \o/ Cheers, V [Ag] _|_ LOOKING FOR GNU EMACS DEVELOPMENT Andy Gaynor 201-545-0458 81 Hassart St, New Brunswick, NJ 08901 gaynor@topaz.rutgers.edu ...!rutgers!topaz.rutgers.edu!gaynor "There is no Editor but Emacs, and Lisp is its Prophet."