Xref: utzoo comp.emacs:9575 gnu.emacs.help:383 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!apple!olivea!mintaka!mintaka!mic From: mic@theory.lcs.mit.edu (Michelangelo Grigni) Newsgroups: comp.emacs,gnu.emacs.help Subject: Re: Changing dired functions without copying Message-ID: <1990Nov21.153637.21870@mintaka.lcs.mit.edu> Date: 21 Nov 90 15:36:37 GMT References: <1990Nov20.211322.11306@julius.cs.uiuc.edu> Sender: daemon@mintaka.lcs.mit.edu (Lucifer Maleficius) Organization: MIT Lab for Computer Science Lines: 113 In-Reply-To: liberte@cs.uiuc.edu's message of 21 Nov 90 01:56:17 GMT From Daniel LaLiberte : > A more general scheme of "shadowing" definitions than depending on a > -hook for each file would be something like the following: > > 1. Name your file of shadow definitions with the same name as the > file with the standard definitions, but put it in a different > directory that is earlier on your load-path. Thus it will be > loaded first. > ... > I invite comments on this scheme, or the problem in general. Yes, I've used this kind of scheme for a couple of years, it has the advantage that shadowed modes are not explicitly mentioned in your ~/.emacs, so you do not have to go changing .emacs nearly as often; rather you go change the appropriate "shadow file". It has the disadvantage that your shadowed definitions may no longer be appropriate if the 'default' source is updated, and they will be ignored if emacs is rebuilt with such packages preloaded. How: early in ~/.emacs I define a default-load function, which loads using the startup value of load-path. I then modify the load-path to start with my shadowing directory ~/el. All my shadowing files then look something like (eg "~/el/dired.el"): (default-load "dired") (defvar ...) ... (defun ...) ... This scheme is complicated by the fact that while default-load'ing the file, I still want load-path bound to my expanded path, in case the default file triggers the loading of further packages. Relevant ~/.emacs code appended (best byte-compiled). I make the comment that this would be cleaner if a version of expand-load-file-name were available from inside elisp. --- Michelangelo Grigni ;; -*- emacs-lisp -*- (defvar default-load-path load-path "Startup value of load-path.") (setq load-path (apply 'nconc (mapcar (function (lambda (dir) (if (file-directory-p dir) (list (expand-file-name dir))))) (append ;; higher priority directories: '("~/el" "~/el/gnus" "/a/aviary/emacs") ;; default directories: default-load-path ;; lower priority directories: '("~bard/emacs") )))) (defun expand-load-file-name (file &optional no-suff path) "\ Find full name of FILE that (load FILE) would load, or nil if none. Optional second argument NO-SUFF is like the optional fourth argument for load, i.e. don't try adding suffixes \".elc\" and \".el\". Optional third argument PATH specifies a different search path (the default is load-path)." (or path (setq path load-path)) (if (file-name-absolute-p file) (setq path (list (file-name-directory file)) file (file-name-nondirectory file))) (let ((suffixes-to-try (cond ((consp no-suff) no-suff) ;; undocumented hook here ((or no-suff (string-match "\\.elc?$" file)) '("")) (t '(".elc" ".el"))))) (let (found suffixes) (while (and path (not found)) (setq suffixes suffixes-to-try) (while (and suffixes (not found)) (let ((try (expand-file-name (concat file (car suffixes)) (car path)))) (if (file-exists-p try) (setq found try))) (setq suffixes (cdr suffixes))) (setq path (cdr path))) found))) ;; Examples: ;; (expand-load-file-name "x-mouse") ;; (expand-load-file-name "term/vt100") ;; (expand-load-file-name "term/vt100" nil default-load-path) (defun default-load (file &optional miss-ok no-mess no-suff bind) "\ Load FILE using default-load-path as load-path. The remaining optional arguments are the same as for load, except the new optional fifth argument BIND non-nil means to dynamically bind load-path to default-load-path during the load (this may matter to recursive loads)." (let ((fullname (expand-load-file-name file no-suff default-load-path))) (if fullname (if bind (let ((load-path default-load-path)) (load fullname nil no-mess t)) (load fullname nil no-mess t)) (or miss-ok (error "Cannot open default-load file: %s" file)) nil))) (defun distrib-load (file &optional miss-ok no-mess no-suff) "\ Load FILE from the distribution ../lisp directory. Remaining optional arguments are the same as for load." (load (expand-file-name file (expand-file-name "../lisp" exec-directory)) miss-ok no-mess no-suff)) -- Michelangelo Grigni 253-1365 NE43-346