emacs-devel
[Top][All Lists]
Advanced

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

desktop and tilde-expand-file-name


From: Lars Hansen
Subject: desktop and tilde-expand-file-name
Date: Sun, 29 Dec 2002 10:14:38 +0100
User-agent: Mozilla/5.0 (Windows; U; Win 9x 4.90; en-US; rv:1.2.1) Gecko/20021130

Hi

I have written some enhancements for the desktop module, and I would like to propose them for the Emacs distribution. A description of the enhancements is included below. But I have two questions:

1. How do I do? I have not participated in Emacs development before, and I don't have CVS. 2. For use in the desktop module, I need a function `tilde-expand-file-name' that should work like `expand-file-name' except that path is specified from "~" rather than from root when that is possible. Such a function allows desktop modules to be portable. But the implementation, listed below, is not good. Can anyone sugest something better? In particular the implementation should not refer to Tramp.

;;;###autoload
(defun tilde-expand-file-name (file-name &optional default-dir)
;; Don't use parameter name `default-directory' here! Then `expand-file-name' will
;; see the parameter instead of the buffer-local variable of the same name.
"Works like `expand-file-name' except that path is specified from \"~\"
rather than form root when possible.
\(It can be impossible on MSDOS and Windows when the FILE-NAME and \"~\"
are on different drives.)
"
  (if
     (and
        (fboundp 'tramp-tramp-file-p)
        (or
           (tramp-tramp-file-p file-name)
           (and default-dir (tramp-tramp-file-p default-dir))
           (and (not default-dir) (tramp-tramp-file-p default-directory))
        )
     )
     (expand-file-name file-name default-dir)
     (let (
(relative-name (file-relative-name (expand-file-name file-name default-dir) "~"))
     )
        (cond
           ((file-name-absolute-p relative-name) relative-name)
           ((string= "./" relative-name) "~/")
           ((string= "." relative-name) "~")
           (t (concat "~/" relative-name))
        )
     )
  )
)

Enhancements for the desktop module:

;;  1. Customizable variable `desktop-save' introduced.
;; When the user changes desktop or quits emacs, should the desktop be saved?
;;        t          -- Allways save.
;;        ask        -- Ask.
;;        ask-if-new -- Ask if no desktop file exists, otherwise just save.
;;        nil        -- Never.
;;     The desktop is never saved when `desktop-enable' is nil"
;;  2. Customizable variable `desktop-path' introduced.
;;     List of directories in which to lookup the desktop file.
;;  3. Customizable hook `desktop-after-read-hook' introduced.
;; It is run after a desktop is read. It can be used to e.g. show a buffer list.
;;  4. Customizable hook `desktop-no-desktop-file-hook' introduced.
;; It is run when no desktop file is found. By default a dired buffer is shown.
;;  5. Customizable variable `desktop-globals-to-save' introduced.
;;  6. Customizable variable `desktop-globals-to-clear' introduced.
;;  7. Command line option --no-desktop introduced.
;;     When this is specified, no desktop file is loaded.
;; 8. Functions `desktop-create-buffer' and `desktop-buffer-dired-misc-data' write file
;;     names in portable form using `tilde-expand-file-name'.
;; 9. Previously the desktop module wrote buffers in the desktop file in the reverse order ;; of the buffer list. Morover restoring buffers in the same order depended on handlers ;; to not change the order of the buffer list and to put newly created buffers at the ;; top of the list. The new module writes buffers in the desktop file in the same order ;; as the buffer list, and the dependence of handlers just described is removed. The ;; change is backwards compatible in the sense that old desktop files are handled in the
;;     same way as the were with the old module.
;; 10. New function `desktop-change-dir'.
;; Saves and clears the desktop, changes to directory DIR and loads the desktop there
;;     indepentently of the value of `desktop-path'.
;; If `desktop-enable' was nil at call, the desktop is not saved, but `desktop-enable' is
;;     subsequently set to t.
;; 11. New function `desktop-save-in-load-dir'.
;;     Save desktop in directory from witch it was loaded.
;; 12. New function `desktop-revert'. Revert to the last loaded desktop.

Lars Hansen





reply via email to

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