1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-12-20 10:23:57 +00:00
emacs/lisp/rfn-eshadow.el

245 lines
9.3 KiB
EmacsLisp
Raw Normal View History

2001-10-05 13:29:25 +00:00
;;; rfn-eshadow.el --- Highlight `shadowed' part of read-file-name input text
;;
;; Copyright (C) 2000-2011 Free Software Foundation, Inc.
2001-10-05 13:29:25 +00:00
;;
;; Author: Miles Bader <miles@gnu.org>
;; Keywords: convenience minibuffer
;; Package: emacs
2001-10-05 13:29:25 +00:00
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
2001-10-05 13:29:25 +00:00
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
2001-10-05 13:29:25 +00:00
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
2001-10-05 13:29:25 +00:00
;;; Commentary:
;;
;; Defines the mode `file-name-shadow-mode'.
2001-10-05 13:29:25 +00:00
;;
;; The `read-file-name' function passes its result through
;; `substitute-in-file-name', so any part of the string preceding
;; multiple slashes (or a drive indicator on MS-DOS/MS-Windows) is
;; ignored.
;;
;; If `file-name-shadow-mode' is active, any part of the
2001-10-05 13:29:25 +00:00
;; minibuffer text that would be ignored because of this is given the
;; properties in `file-name-shadow-properties', which may
2001-10-05 13:29:25 +00:00
;; be used to make the ignored text invisible, dim, etc.
;;
;;; Code:
;;; Customization
(defconst file-name-shadow-properties-custom-type
2001-10-05 13:29:25 +00:00
'(list
(checklist :inline t
(const :tag "Invisible"
:doc "Make shadowed part of filename invisible"
:format "%t%n%h"
:inline t
(invisible t intangible t))
(list :inline t
:format "%v"
:tag "Face"
:doc "Display shadowed part of filename using a different face"
(const :format "" face)
(face :value file-name-shadow))
2001-10-05 13:29:25 +00:00
(list :inline t
:format "%t: %v%h"
:tag "Brackets"
;; Note the 4 leading spaces in the doc string;
;; this is hack to get around the fact that the
;; newline after the second string widget comes
;; from the string widget, and doesn't indent
;; correctly. We could use a :size attribute to
;; make the second string widget not have a
;; terminating newline, but this makes it impossible
;; to enter trailing whitespace, and it's desirable
;; that it be possible.
:doc " Surround shadowed part of filename with brackets"
(const :format "" before-string)
(string :format "%v" :size 4 :value "{")
(const :format "" after-string)
;; see above about why the 2nd string doesn't use :size
(string :format " and: %v" :value "} "))
(list :inline t
:format "%t: %v%n%h"
:tag "String"
:doc "Display a string instead of the shadowed part of filename"
(const :format "" display)
(string :format "%v" :size 15 :value "<...ignored...>"))
(const :tag "Avoid"
:doc "Try to keep cursor out of shadowed part of filename"
:format "%t%n%h"
:inline t
(field shadow)))
(repeat :inline t
:tag "Other Properties"
(list :inline t
:format "%v"
(symbol :tag "Property")
(sexp :tag "Value")))))
(defcustom file-name-shadow-properties
* textmodes/tex-mode.el (tex-alt-dvi-print-command) (tex-dvi-print-command, tex-bibtex-command, tex-start-commands) (tex-start-options, slitex-run-command, latex-run-command) (tex-run-command, tex-directory): * textmodes/ispell.el (ispell-html-skip-alists) (ispell-tex-skip-alists, ispell-tex-skip-alists): * textmodes/fill.el (adaptive-fill-first-line-regexp): (adaptive-fill-regexp): * textmodes/dns-mode.el (auto-mode-alist): * progmodes/python.el (interpreter-mode-alist): * progmodes/etags.el (tags-compression-info-list): * progmodes/etags.el (tags-file-name): * net/browse-url.el (browse-url-galeon-program) (browse-url-firefox-program): * mail/sendmail.el (mail-signature-file) (mail-citation-prefix-regexp): * international/mule-conf.el (eight-bit): * international/latexenc.el (latex-inputenc-coding-alist): * international/fontset.el (x-pixel-size-width-font-regexp): * emacs-lisp/warnings.el (warning-type-format): * emacs-lisp/trace.el (trace-buffer): * emacs-lisp/lisp-mode.el (lisp-interaction-mode-map) (emacs-lisp-mode-map): * calendar/holidays.el (holiday-solar-holidays) (holiday-bahai-holidays, holiday-islamic-holidays) (holiday-christian-holidays, holiday-hebrew-holidays) (hebrew-holidays-4, hebrew-holidays-3, hebrew-holidays-2) (hebrew-holidays-1, holiday-oriental-holidays) (holiday-general-holidays): * x-dnd.el (x-dnd-known-types): * tool-bar.el (tool-bar): * startup.el (site-run-file): * shell.el (shell-dumb-shell-regexp): * rfn-eshadow.el (file-name-shadow-tty-properties) (file-name-shadow-properties): * paths.el (remote-shell-program, news-directory): * mouse.el ([C-down-mouse-3]): * menu-bar.el (menu-bar-tools-menu): * jka-cmpr-hook.el (jka-compr-load-suffixes) (jka-compr-mode-alist-additions, jka-compr-compression-info-list) (jka-compr-compression-info-list): * isearch.el (search-whitespace-regexp): * image-file.el (image-file-name-extensions): * find-dired.el (find-ls-option): * files.el (directory-listing-before-filename-regexp) (directory-free-space-args, insert-directory-program) (list-directory-brief-switches, magic-fallback-mode-alist) (magic-fallback-mode-alist, auto-mode-interpreter-regexp) (automount-dir-prefix): * faces.el (face-x-resources, x-font-regexp, x-font-regexp-head) (x-font-regexp-slant, x-font-regexp-weight, face-x-resources) (face-font-registry-alternatives, face-font-registry-alternatives) (face-font-family-alternatives): * facemenu.el (facemenu-add-new-face, facemenu-background-menu) (facemenu-foreground-menu, facemenu-face-menu): * epa-hook.el (epa-file-name-regexp): * dnd.el (dnd-protocol-alist): * textmodes/rst.el (auto-mode-alist): * button.el (default-button): Purecopy strings.
2009-11-06 05:16:23 +00:00
;; FIXME: should we purecopy this?
'(face file-name-shadow field shadow)
2001-10-05 13:29:25 +00:00
"Properties given to the `shadowed' part of a filename in the minibuffer.
Only used when `file-name-shadow-mode' is active.
If Emacs is not running under a window system,
`file-name-shadow-tty-properties' is used instead."
:type file-name-shadow-properties-custom-type
:group 'minibuffer
:version "22.1")
2001-10-05 13:29:25 +00:00
(defcustom file-name-shadow-tty-properties
* textmodes/tex-mode.el (tex-alt-dvi-print-command) (tex-dvi-print-command, tex-bibtex-command, tex-start-commands) (tex-start-options, slitex-run-command, latex-run-command) (tex-run-command, tex-directory): * textmodes/ispell.el (ispell-html-skip-alists) (ispell-tex-skip-alists, ispell-tex-skip-alists): * textmodes/fill.el (adaptive-fill-first-line-regexp): (adaptive-fill-regexp): * textmodes/dns-mode.el (auto-mode-alist): * progmodes/python.el (interpreter-mode-alist): * progmodes/etags.el (tags-compression-info-list): * progmodes/etags.el (tags-file-name): * net/browse-url.el (browse-url-galeon-program) (browse-url-firefox-program): * mail/sendmail.el (mail-signature-file) (mail-citation-prefix-regexp): * international/mule-conf.el (eight-bit): * international/latexenc.el (latex-inputenc-coding-alist): * international/fontset.el (x-pixel-size-width-font-regexp): * emacs-lisp/warnings.el (warning-type-format): * emacs-lisp/trace.el (trace-buffer): * emacs-lisp/lisp-mode.el (lisp-interaction-mode-map) (emacs-lisp-mode-map): * calendar/holidays.el (holiday-solar-holidays) (holiday-bahai-holidays, holiday-islamic-holidays) (holiday-christian-holidays, holiday-hebrew-holidays) (hebrew-holidays-4, hebrew-holidays-3, hebrew-holidays-2) (hebrew-holidays-1, holiday-oriental-holidays) (holiday-general-holidays): * x-dnd.el (x-dnd-known-types): * tool-bar.el (tool-bar): * startup.el (site-run-file): * shell.el (shell-dumb-shell-regexp): * rfn-eshadow.el (file-name-shadow-tty-properties) (file-name-shadow-properties): * paths.el (remote-shell-program, news-directory): * mouse.el ([C-down-mouse-3]): * menu-bar.el (menu-bar-tools-menu): * jka-cmpr-hook.el (jka-compr-load-suffixes) (jka-compr-mode-alist-additions, jka-compr-compression-info-list) (jka-compr-compression-info-list): * isearch.el (search-whitespace-regexp): * image-file.el (image-file-name-extensions): * find-dired.el (find-ls-option): * files.el (directory-listing-before-filename-regexp) (directory-free-space-args, insert-directory-program) (list-directory-brief-switches, magic-fallback-mode-alist) (magic-fallback-mode-alist, auto-mode-interpreter-regexp) (automount-dir-prefix): * faces.el (face-x-resources, x-font-regexp, x-font-regexp-head) (x-font-regexp-slant, x-font-regexp-weight, face-x-resources) (face-font-registry-alternatives, face-font-registry-alternatives) (face-font-family-alternatives): * facemenu.el (facemenu-add-new-face, facemenu-background-menu) (facemenu-foreground-menu, facemenu-face-menu): * epa-hook.el (epa-file-name-regexp): * dnd.el (dnd-protocol-alist): * textmodes/rst.el (auto-mode-alist): * button.el (default-button): Purecopy strings.
2009-11-06 05:16:23 +00:00
(purecopy '(before-string "{" after-string "} " field shadow))
2001-10-05 13:29:25 +00:00
"Properties given to the `shadowed' part of a filename in the minibuffer.
Only used when `file-name-shadow-mode' is active and Emacs
is not running under a window-system; if Emacs is running under a window
system, `file-name-shadow-properties' is used instead."
:type file-name-shadow-properties-custom-type
:group 'minibuffer
:version "22.1")
2001-10-05 13:29:25 +00:00
(defface file-name-shadow
'((t :inherit shadow))
"Face used by `file-name-shadow-mode' for the shadow."
:group 'minibuffer
:version "22.1")
2001-10-05 13:29:25 +00:00
(defvar rfn-eshadow-setup-minibuffer-hook nil
"Minibuffer setup functions from other packages.")
(defvar rfn-eshadow-update-overlay-hook nil
"Customer overlay functions from other packages")
2001-10-05 13:29:25 +00:00
;;; Internal variables
;; A list of minibuffers to which we've added a post-command-hook.
(defvar rfn-eshadow-frobbed-minibufs nil)
;; An overlay covering the shadowed part of the filename (local to the
;; minibuffer).
(defvar rfn-eshadow-overlay)
(make-variable-buffer-local 'rfn-eshadow-overlay)
;;; Hook functions
;; This function goes on minibuffer-setup-hook
(defun rfn-eshadow-setup-minibuffer ()
"Set up a minibuffer for `file-name-shadow-mode'.
2001-10-05 13:29:25 +00:00
The prompt and initial input should already have been inserted."
(when minibuffer-completing-file-name
(setq rfn-eshadow-overlay
(make-overlay (minibuffer-prompt-end) (minibuffer-prompt-end)))
;; Give rfn-eshadow-overlay the user's props.
(let ((props
(if window-system
file-name-shadow-properties
file-name-shadow-tty-properties)))
2001-10-05 13:29:25 +00:00
(while props
(overlay-put rfn-eshadow-overlay (pop props) (pop props))))
;; Turn on overlay evaporation so that we don't have to worry about
;; odd effects when the overlay sits empty at the beginning of the
;; minibuffer.
(overlay-put rfn-eshadow-overlay 'evaporate t)
;; Add our post-command hook, and make sure can remove it later.
(add-to-list 'rfn-eshadow-frobbed-minibufs (current-buffer))
(add-hook 'post-command-hook #'rfn-eshadow-update-overlay nil t)
;; Run custom hook
(run-hooks 'rfn-eshadow-setup-minibuffer-hook)))
2001-10-05 13:29:25 +00:00
(defsubst rfn-eshadow-sifn-equal (goal pos)
(equal goal (condition-case nil
(substitute-in-file-name
(buffer-substring-no-properties pos (point-max)))
;; `substitute-in-file-name' can fail on partial input.
(error nil))))
2001-10-05 13:29:25 +00:00
;; post-command-hook to update overlay
(defun rfn-eshadow-update-overlay ()
"Update `rfn-eshadow-overlay' to cover shadowed part of minibuffer input.
This is intended to be used as a minibuffer `post-command-hook' for
`file-name-shadow-mode'; the minibuffer should have already
2001-10-05 13:29:25 +00:00
been set up by `rfn-eshadow-setup-minibuffer'."
(condition-case nil
(let ((goal (substitute-in-file-name (minibuffer-contents)))
(mid (overlay-end rfn-eshadow-overlay))
(start (minibuffer-prompt-end))
(end (point-max)))
(unless
;; Catch the common case where the shadow does not need to move.
(and mid
(or (eq mid end)
(not (rfn-eshadow-sifn-equal goal (1+ mid))))
(or (eq mid start)
(rfn-eshadow-sifn-equal goal mid)))
;; Binary search for the greatest position still equivalent to
;; the whole.
(while (or (< (1+ start) end)
(if (and (< (1+ end) (point-max))
(rfn-eshadow-sifn-equal goal (1+ end)))
;; (SIFN end) != goal, but (SIFN (1+end)) == goal,
;; We've reached a discontinuity: this can happen
;; e.g. if `end' point to "/:...".
(setq start (1+ end) end (point-max))))
(setq mid (/ (+ start end) 2))
(if (rfn-eshadow-sifn-equal goal mid)
(setq start mid)
(setq end mid)))
(move-overlay rfn-eshadow-overlay (minibuffer-prompt-end) start))
;; Run custom hook
(run-hooks 'rfn-eshadow-update-overlay-hook))
;; `substitute-in-file-name' can fail on partial input.
(error nil)))
2001-10-05 13:29:25 +00:00
(define-minor-mode file-name-shadow-mode
Fix minor mode docstrings for the new meaning of a nil ARG. * abbrev.el (abbrev-mode): * allout.el (allout-mode): * autoinsert.el (auto-insert-mode): * autoarg.el (autoarg-mode, autoarg-kp-mode): * autorevert.el (auto-revert-mode, auto-revert-tail-mode) (global-auto-revert-mode): * battery.el (display-battery-mode): * composite.el (global-auto-composition-mode) (auto-composition-mode): * delsel.el (delete-selection-mode): * desktop.el (desktop-save-mode): * dired-x.el (dired-omit-mode): * dirtrack.el (dirtrack-mode): * doc-view.el (doc-view-minor-mode): * double.el (double-mode): * electric.el (electric-indent-mode, electric-pair-mode): * emacs-lock.el (emacs-lock-mode): * epa-hook.el (auto-encryption-mode): * follow.el (follow-mode): * font-core.el (font-lock-mode): * frame.el (auto-raise-mode, auto-lower-mode, blink-cursor-mode): * help.el (temp-buffer-resize-mode): * hilit-chg.el (highlight-changes-mode) (highlight-changes-visible-mode): * hi-lock.el (hi-lock-mode): * hl-line.el (hl-line-mode, global-hl-line-mode): * icomplete.el (icomplete-mode): * ido.el (ido-everywhere): * image-file.el (auto-image-file-mode): * image-mode.el (image-minor-mode): * iswitchb.el (iswitchb-mode): * jka-cmpr-hook.el (auto-compression-mode): * linum.el (linum-mode): * longlines.el (longlines-mode): * master.el (master-mode): * mb-depth.el (minibuffer-depth-indicate-mode): * menu-bar.el (menu-bar-mode): * minibuf-eldef.el (minibuffer-electric-default-mode): * mouse-sel.el (mouse-sel-mode): * msb.el (msb-mode): * mwheel.el (mouse-wheel-mode): * outline.el (outline-minor-mode): * paren.el (show-paren-mode): * recentf.el (recentf-mode): * reveal.el (reveal-mode, global-reveal-mode): * rfn-eshadow.el (file-name-shadow-mode): * ruler-mode.el (ruler-mode): * savehist.el (savehist-mode): * scroll-all.el (scroll-all-mode): * scroll-bar.el (scroll-bar-mode): * server.el (server-mode): * shell.el (shell-dirtrack-mode): * simple.el (auto-fill-mode, transient-mark-mode) (visual-line-mode, overwrite-mode, binary-overwrite-mode) (line-number-mode, column-number-mode, size-indication-mode) (auto-save-mode, normal-erase-is-backspace-mode, visible-mode): * strokes.el (strokes-mode): * time.el (display-time-mode): * t-mouse.el (gpm-mouse-mode): * tool-bar.el (tool-bar-mode): * tooltip.el (tooltip-mode): * type-break.el (type-break-mode-line-message-mode) (type-break-query-mode): * view.el (view-mode): * whitespace.el (whitespace-mode, whitespace-newline-mode) (global-whitespace-mode, global-whitespace-newline-mode): * xt-mouse.el (xterm-mouse-mode): Doc fix. * emacs-lisp/easy-mmode.el (define-globalized-minor-mode): Fix autogenerated docstring.
2011-10-19 12:54:24 +00:00
"Toggle file-name shadowing in minibuffers (File-Name Shadow mode).
With a prefix argument ARG, enable File-Name Shadow mode if ARG
is positive, and disable it otherwise. If called from Lisp,
enable the mode if ARG is omitted or nil.
File-Name Shadow mode is a global minor mode. When enabled, any
part of a filename being read in the minibuffer that would be
ignored (because the result is passed through
2002-08-26 01:10:46 +00:00
`substitute-in-file-name') is given the properties in
Fix minor mode docstrings for the new meaning of a nil ARG. * abbrev.el (abbrev-mode): * allout.el (allout-mode): * autoinsert.el (auto-insert-mode): * autoarg.el (autoarg-mode, autoarg-kp-mode): * autorevert.el (auto-revert-mode, auto-revert-tail-mode) (global-auto-revert-mode): * battery.el (display-battery-mode): * composite.el (global-auto-composition-mode) (auto-composition-mode): * delsel.el (delete-selection-mode): * desktop.el (desktop-save-mode): * dired-x.el (dired-omit-mode): * dirtrack.el (dirtrack-mode): * doc-view.el (doc-view-minor-mode): * double.el (double-mode): * electric.el (electric-indent-mode, electric-pair-mode): * emacs-lock.el (emacs-lock-mode): * epa-hook.el (auto-encryption-mode): * follow.el (follow-mode): * font-core.el (font-lock-mode): * frame.el (auto-raise-mode, auto-lower-mode, blink-cursor-mode): * help.el (temp-buffer-resize-mode): * hilit-chg.el (highlight-changes-mode) (highlight-changes-visible-mode): * hi-lock.el (hi-lock-mode): * hl-line.el (hl-line-mode, global-hl-line-mode): * icomplete.el (icomplete-mode): * ido.el (ido-everywhere): * image-file.el (auto-image-file-mode): * image-mode.el (image-minor-mode): * iswitchb.el (iswitchb-mode): * jka-cmpr-hook.el (auto-compression-mode): * linum.el (linum-mode): * longlines.el (longlines-mode): * master.el (master-mode): * mb-depth.el (minibuffer-depth-indicate-mode): * menu-bar.el (menu-bar-mode): * minibuf-eldef.el (minibuffer-electric-default-mode): * mouse-sel.el (mouse-sel-mode): * msb.el (msb-mode): * mwheel.el (mouse-wheel-mode): * outline.el (outline-minor-mode): * paren.el (show-paren-mode): * recentf.el (recentf-mode): * reveal.el (reveal-mode, global-reveal-mode): * rfn-eshadow.el (file-name-shadow-mode): * ruler-mode.el (ruler-mode): * savehist.el (savehist-mode): * scroll-all.el (scroll-all-mode): * scroll-bar.el (scroll-bar-mode): * server.el (server-mode): * shell.el (shell-dirtrack-mode): * simple.el (auto-fill-mode, transient-mark-mode) (visual-line-mode, overwrite-mode, binary-overwrite-mode) (line-number-mode, column-number-mode, size-indication-mode) (auto-save-mode, normal-erase-is-backspace-mode, visible-mode): * strokes.el (strokes-mode): * time.el (display-time-mode): * t-mouse.el (gpm-mouse-mode): * tool-bar.el (tool-bar-mode): * tooltip.el (tooltip-mode): * type-break.el (type-break-mode-line-message-mode) (type-break-query-mode): * view.el (view-mode): * whitespace.el (whitespace-mode, whitespace-newline-mode) (global-whitespace-mode, global-whitespace-newline-mode): * xt-mouse.el (xterm-mouse-mode): Doc fix. * emacs-lisp/easy-mmode.el (define-globalized-minor-mode): Fix autogenerated docstring.
2011-10-19 12:54:24 +00:00
`file-name-shadow-properties', which can be used to make that
portion dim, invisible, or otherwise less visually noticeable."
2001-10-05 13:29:25 +00:00
:global t
;; We'd like to use custom-initialize-set here so the setup is done
;; before dumping, but at the point where the defcustom is evaluated,
;; the corresponding function isn't defined yet, so
;; custom-initialize-set signals an error.
:initialize 'custom-initialize-delay
:init-value t
2001-10-05 13:29:25 +00:00
:group 'minibuffer
:version "22.1"
(if file-name-shadow-mode
2001-10-05 13:29:25 +00:00
;; Enable the mode
(add-hook 'minibuffer-setup-hook 'rfn-eshadow-setup-minibuffer)
;; Disable the mode
(remove-hook 'minibuffer-setup-hook 'rfn-eshadow-setup-minibuffer)
;; Remove our entry from any post-command-hook variable's it's still in
(dolist (minibuf rfn-eshadow-frobbed-minibufs)
(with-current-buffer minibuf
(remove-hook 'post-command-hook #'rfn-eshadow-update-overlay t)))
(setq rfn-eshadow-frobbed-minibufs nil)))
(provide 'rfn-eshadow)
;;; rfn-eshadow.el ends here