mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-21 21:20:44 -08:00
This reverts almost all my recent changes to use curved quotes in docstrings and/or strings used for error diagnostics. There are a few exceptions, e.g., Bahá’í proper names. * admin/unidata/unidata-gen.el (unidata-gen-table): * lisp/abbrev.el (expand-region-abbrevs): * lisp/align.el (align-region): * lisp/allout.el (allout-mode, allout-solicit-alternate-bullet) (outlineify-sticky): * lisp/apropos.el (apropos-library): * lisp/bookmark.el (bookmark-default-annotation-text): * lisp/button.el (button-category-symbol, button-put) (make-text-button): * lisp/calc/calc-aent.el (math-read-if, math-read-factor): * lisp/calc/calc-embed.el (calc-do-embedded): * lisp/calc/calc-ext.el (calc-user-function-list): * lisp/calc/calc-graph.el (calc-graph-show-dumb): * lisp/calc/calc-help.el (calc-describe-key) (calc-describe-thing, calc-full-help): * lisp/calc/calc-lang.el (calc-c-language) (math-parse-fortran-vector-end, math-parse-tex-sum) (math-parse-eqn-matrix, math-parse-eqn-prime) (calc-yacas-language, calc-maxima-language, calc-giac-language) (math-read-giac-subscr, math-read-math-subscr) (math-read-big-rec, math-read-big-balance): * lisp/calc/calc-misc.el (calc-help, report-calc-bug): * lisp/calc/calc-mode.el (calc-auto-why, calc-save-modes) (calc-auto-recompute): * lisp/calc/calc-prog.el (calc-fix-token-name) (calc-read-parse-table-part, calc-user-define-invocation) (math-do-arg-check): * lisp/calc/calc-store.el (calc-edit-variable): * lisp/calc/calc-units.el (math-build-units-table-buffer): * lisp/calc/calc-vec.el (math-read-brackets): * lisp/calc/calc-yank.el (calc-edit-mode): * lisp/calc/calc.el (calc, calc-do, calc-user-invocation): * lisp/calendar/appt.el (appt-display-message): * lisp/calendar/diary-lib.el (diary-check-diary-file) (diary-mail-entries, diary-from-outlook): * lisp/calendar/icalendar.el (icalendar-export-region) (icalendar--convert-float-to-ical) (icalendar--convert-date-to-ical) (icalendar--convert-ical-to-diary) (icalendar--convert-recurring-to-diary) (icalendar--add-diary-entry): * lisp/calendar/time-date.el (format-seconds): * lisp/calendar/timeclock.el (timeclock-mode-line-display) (timeclock-make-hours-explicit, timeclock-log-data): * lisp/calendar/todo-mode.el (todo-prefix, todo-delete-category) (todo-item-mark, todo-check-format) (todo-insert-item--next-param, todo-edit-item--next-key) (todo-mode): * lisp/cedet/ede/pmake.el (ede-proj-makefile-insert-dist-rules): * lisp/cedet/mode-local.el (describe-mode-local-overload) (mode-local-print-binding, mode-local-describe-bindings-2): * lisp/cedet/semantic/complete.el (semantic-displayor-show-request): * lisp/cedet/srecode/srt-mode.el (srecode-macro-help): * lisp/cus-start.el (standard): * lisp/cus-theme.el (describe-theme-1): * lisp/custom.el (custom-add-dependencies, custom-check-theme) (custom--sort-vars-1, load-theme): * lisp/descr-text.el (describe-text-properties-1, describe-char): * lisp/dired-x.el (dired-do-run-mail): * lisp/dired.el (dired-log): * lisp/emacs-lisp/advice.el (ad-read-advised-function) (ad-read-advice-class, ad-read-advice-name, ad-enable-advice) (ad-disable-advice, ad-remove-advice, ad-set-argument) (ad-set-arguments, ad--defalias-fset, ad-activate) (ad-deactivate): * lisp/emacs-lisp/byte-opt.el (byte-compile-inline-expand) (byte-compile-unfold-lambda, byte-optimize-form-code-walker) (byte-optimize-while, byte-optimize-apply): * lisp/emacs-lisp/byte-run.el (defun, defsubst): * lisp/emacs-lisp/bytecomp.el (byte-compile-lapcode) (byte-compile-log-file, byte-compile-format-warn) (byte-compile-nogroup-warn, byte-compile-arglist-warn) (byte-compile-cl-warn) (byte-compile-warn-about-unresolved-functions) (byte-compile-file, byte-compile--declare-var) (byte-compile-file-form-defmumble, byte-compile-form) (byte-compile-normal-call, byte-compile-check-variable) (byte-compile-variable-ref, byte-compile-variable-set) (byte-compile-subr-wrong-args, byte-compile-setq-default) (byte-compile-negation-optimizer) (byte-compile-condition-case--old) (byte-compile-condition-case--new, byte-compile-save-excursion) (byte-compile-defvar, byte-compile-autoload) (byte-compile-lambda-form) (byte-compile-make-variable-buffer-local, display-call-tree) (batch-byte-compile): * lisp/emacs-lisp/cconv.el (cconv-convert, cconv--analyze-use): * lisp/emacs-lisp/chart.el (chart-space-usage): * lisp/emacs-lisp/check-declare.el (check-declare-scan) (check-declare-warn, check-declare-file) (check-declare-directory): * lisp/emacs-lisp/checkdoc.el (checkdoc-this-string-valid-engine) (checkdoc-message-text-engine): * lisp/emacs-lisp/cl-extra.el (cl-parse-integer) (cl--describe-class): * lisp/emacs-lisp/cl-generic.el (cl-defgeneric) (cl--generic-describe, cl-generic-generalizers): * lisp/emacs-lisp/cl-macs.el (cl--parse-loop-clause, cl-tagbody) (cl-symbol-macrolet): * lisp/emacs-lisp/cl.el (cl-unload-function, flet): * lisp/emacs-lisp/copyright.el (copyright) (copyright-update-directory): * lisp/emacs-lisp/edebug.el (edebug-read-list): * lisp/emacs-lisp/eieio-base.el (eieio-persistent-read): * lisp/emacs-lisp/eieio-core.el (eieio--slot-override) (eieio-oref): * lisp/emacs-lisp/eieio-opt.el (eieio-help-constructor): * lisp/emacs-lisp/eieio-speedbar.el: (eieio-speedbar-child-make-tag-lines) (eieio-speedbar-child-description): * lisp/emacs-lisp/eieio.el (defclass, change-class): * lisp/emacs-lisp/elint.el (elint-file, elint-get-top-forms) (elint-init-form, elint-check-defalias-form) (elint-check-let-form): * lisp/emacs-lisp/ert.el (ert-get-test, ert-results-mode-menu) (ert-results-pop-to-backtrace-for-test-at-point) (ert-results-pop-to-messages-for-test-at-point) (ert-results-pop-to-should-forms-for-test-at-point) (ert-describe-test): * lisp/emacs-lisp/find-func.el (find-function-search-for-symbol) (find-function-library): * lisp/emacs-lisp/generator.el (iter-yield): * lisp/emacs-lisp/gv.el (gv-define-simple-setter): * lisp/emacs-lisp/lisp-mnt.el (lm-verify): * lisp/emacs-lisp/macroexp.el (macroexp--obsolete-warning): * lisp/emacs-lisp/map-ynp.el (map-y-or-n-p): * lisp/emacs-lisp/nadvice.el (advice--make-docstring) (advice--make, define-advice): * lisp/emacs-lisp/package-x.el (package-upload-file): * lisp/emacs-lisp/package.el (package-version-join) (package-disabled-p, package-activate-1, package-activate) (package--download-one-archive) (package--download-and-read-archives) (package-compute-transaction, package-install-from-archive) (package-install, package-install-selected-packages) (package-delete, package-autoremove, describe-package-1) (package-install-button-action, package-delete-button-action) (package-menu-hide-package, package-menu--list-to-prompt) (package-menu--perform-transaction) (package-menu--find-and-notify-upgrades): * lisp/emacs-lisp/pcase.el (pcase-exhaustive, pcase--u1): * lisp/emacs-lisp/re-builder.el (reb-enter-subexp-mode): * lisp/emacs-lisp/ring.el (ring-previous, ring-next): * lisp/emacs-lisp/rx.el (rx-check, rx-anything) (rx-check-any-string, rx-check-any, rx-check-not, rx-=) (rx-repeat, rx-check-backref, rx-syntax, rx-check-category) (rx-form): * lisp/emacs-lisp/smie.el (smie-config-save): * lisp/emacs-lisp/subr-x.el (internal--check-binding): * lisp/emacs-lisp/tabulated-list.el (tabulated-list-put-tag): * lisp/emacs-lisp/testcover.el (testcover-1value): * lisp/emacs-lisp/timer.el (timer-event-handler): * lisp/emulation/viper-cmd.el (viper-toggle-parse-sexp-ignore-comments) (viper-toggle-search-style, viper-kill-buffer) (viper-brac-function): * lisp/emulation/viper-macs.el (viper-record-kbd-macro): * lisp/env.el (setenv): * lisp/erc/erc-button.el (erc-nick-popup): * lisp/erc/erc.el (erc-cmd-LOAD, erc-handle-login, english): * lisp/eshell/em-dirs.el (eshell/cd): * lisp/eshell/em-glob.el (eshell-glob-regexp) (eshell-glob-entries): * lisp/eshell/em-pred.el (eshell-parse-modifiers): * lisp/eshell/esh-opt.el (eshell-show-usage): * lisp/facemenu.el (facemenu-add-new-face) (facemenu-add-new-color): * lisp/faces.el (read-face-name, read-face-font, describe-face) (x-resolve-font-name): * lisp/files-x.el (modify-file-local-variable): * lisp/files.el (locate-user-emacs-file, find-alternate-file) (set-auto-mode, hack-one-local-variable--obsolete) (dir-locals-set-directory-class, write-file, basic-save-buffer) (delete-directory, copy-directory, recover-session) (recover-session-finish, insert-directory) (file-modes-char-to-who, file-modes-symbolic-to-number) (move-file-to-trash): * lisp/filesets.el (filesets-add-buffer, filesets-remove-buffer): * lisp/find-cmd.el (find-generic, find-to-string): * lisp/finder.el (finder-commentary): * lisp/font-lock.el (font-lock-fontify-buffer): * lisp/format.el (format-write-file, format-find-file) (format-insert-file): * lisp/frame.el (get-device-terminal, select-frame-by-name): * lisp/fringe.el (fringe--check-style): * lisp/gnus/nnmairix.el (nnmairix-widget-create-query): * lisp/help-fns.el (help-fns--key-bindings) (help-fns--compiler-macro, help-fns--parent-mode) (help-fns--obsolete, help-fns--interactive-only) (describe-function-1, describe-variable): * lisp/help.el (describe-mode) (describe-minor-mode-from-indicator): * lisp/image.el (image-type): * lisp/international/ccl.el (ccl-dump): * lisp/international/fontset.el (x-must-resolve-font-name): * lisp/international/mule-cmds.el (prefer-coding-system) (select-safe-coding-system-interactively) (select-safe-coding-system, activate-input-method) (toggle-input-method, describe-current-input-method) (describe-language-environment): * lisp/international/mule-conf.el (code-offset): * lisp/international/mule-diag.el (describe-character-set) (list-input-methods-1): * lisp/mail/feedmail.el (feedmail-run-the-queue): * lisp/mouse.el (minor-mode-menu-from-indicator): * lisp/mpc.el (mpc-playlist-rename): * lisp/msb.el (msb--choose-menu): * lisp/net/ange-ftp.el (ange-ftp-shell-command): * lisp/net/imap.el (imap-interactive-login): * lisp/net/mairix.el (mairix-widget-create-query): * lisp/net/newst-backend.el (newsticker--sentinel-work): * lisp/net/newst-treeview.el (newsticker--treeview-load): * lisp/net/rlogin.el (rlogin): * lisp/obsolete/iswitchb.el (iswitchb-possible-new-buffer): * lisp/obsolete/otodo-mode.el (todo-more-important-p): * lisp/obsolete/pgg-gpg.el (pgg-gpg-process-region): * lisp/obsolete/pgg-pgp.el (pgg-pgp-process-region): * lisp/obsolete/pgg-pgp5.el (pgg-pgp5-process-region): * lisp/org/ob-core.el (org-babel-goto-named-src-block) (org-babel-goto-named-result): * lisp/org/ob-fortran.el (org-babel-fortran-ensure-main-wrap): * lisp/org/ob-ref.el (org-babel-ref-resolve): * lisp/org/org-agenda.el (org-agenda-prepare): * lisp/org/org-clock.el (org-clock-notify-once-if-expired) (org-clock-resolve): * lisp/org/org-ctags.el (org-ctags-ask-rebuild-tags-file-then-find-tag): * lisp/org/org-feed.el (org-feed-parse-atom-entry): * lisp/org/org-habit.el (org-habit-parse-todo): * lisp/org/org-mouse.el (org-mouse-popup-global-menu) (org-mouse-context-menu): * lisp/org/org-table.el (org-table-edit-formulas): * lisp/org/ox.el (org-export-async-start): * lisp/proced.el (proced-log): * lisp/progmodes/ada-mode.el (ada-get-indent-case) (ada-check-matching-start, ada-goto-matching-start): * lisp/progmodes/ada-prj.el (ada-prj-display-page): * lisp/progmodes/ada-xref.el (ada-find-executable): * lisp/progmodes/ebrowse.el (ebrowse-tags-apropos): * lisp/progmodes/etags.el (etags-tags-apropos-additional): * lisp/progmodes/flymake.el (flymake-parse-err-lines) (flymake-start-syntax-check-process): * lisp/progmodes/python.el (python-shell-get-process-or-error) (python-define-auxiliary-skeleton): * lisp/progmodes/sql.el (sql-comint): * lisp/progmodes/verilog-mode.el (verilog-load-file-at-point): * lisp/progmodes/vhdl-mode.el (vhdl-widget-directory-validate): * lisp/recentf.el (recentf-open-files): * lisp/replace.el (query-replace-read-from) (occur-after-change-function, occur-1): * lisp/scroll-bar.el (scroll-bar-columns): * lisp/server.el (server-get-auth-key): * lisp/simple.el (execute-extended-command) (undo-outer-limit-truncate, list-processes--refresh) (compose-mail, set-variable, choose-completion-string) (define-alternatives): * lisp/startup.el (site-run-file, tty-handle-args, command-line) (command-line-1): * lisp/subr.el (noreturn, define-error, add-to-list) (read-char-choice, version-to-list): * lisp/term/common-win.el (x-handle-xrm-switch) (x-handle-name-switch, x-handle-args): * lisp/term/x-win.el (x-handle-parent-id, x-handle-smid): * lisp/textmodes/reftex-ref.el (reftex-label): * lisp/textmodes/reftex-toc.el (reftex-toc-rename-label): * lisp/textmodes/two-column.el (2C-split): * lisp/tutorial.el (tutorial--describe-nonstandard-key) (tutorial--find-changed-keys): * lisp/type-break.el (type-break-noninteractive-query): * lisp/wdired.el (wdired-do-renames, wdired-do-symlink-changes) (wdired-do-perm-changes): * lisp/whitespace.el (whitespace-report-region): Prefer grave quoting in source-code strings used to generate help and diagnostics. * lisp/faces.el (face-documentation): No need to convert quotes, since the result is a docstring. * lisp/info.el (Info-virtual-index-find-node) (Info-virtual-index, info-apropos): Simplify by generating only curved quotes, since info files are typically that ways nowadays anyway. * lisp/international/mule-diag.el (list-input-methods): Don’t assume text quoting style is curved. * lisp/org/org-bibtex.el (org-bibtex-fields): Revert my recent changes, going back to the old quoting style.
577 lines
19 KiB
EmacsLisp
577 lines
19 KiB
EmacsLisp
;;; em-dirs.el --- directory navigation commands -*- lexical-binding:t -*-
|
|
|
|
;; Copyright (C) 1999-2015 Free Software Foundation, Inc.
|
|
|
|
;; Author: John Wiegley <johnw@gnu.org>
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
|
;; 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.
|
|
|
|
;; 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/>.
|
|
|
|
;;; Commentary:
|
|
|
|
;; The only special feature that Eshell offers in the last-dir-ring.
|
|
;; To view the ring, enter:
|
|
;;
|
|
;; cd =
|
|
;;
|
|
;; Changing to an index within the ring is done using:
|
|
;;
|
|
;; cd - ; same as cd -0
|
|
;; cd -4
|
|
;;
|
|
;; Or, it is possible to change the first member in the ring which
|
|
;; matches a regexp:
|
|
;;
|
|
;; cd =bcc ; change to the last directory visited containing "bcc"
|
|
;;
|
|
;; This ring is maintained automatically, and is persisted across
|
|
;; Eshell sessions. It is a separate mechanism from `pushd' and
|
|
;; `popd', and the two may be used at the same time.
|
|
|
|
;;; Code:
|
|
|
|
(require 'eshell)
|
|
(require 'ring)
|
|
(require 'esh-opt)
|
|
|
|
;;;###autoload
|
|
(progn
|
|
(defgroup eshell-dirs nil
|
|
"Directory navigation involves changing directories, examining the
|
|
current directory, maintaining a directory stack, and also keeping
|
|
track of a history of the last directory locations the user was in.
|
|
Emacs does provide standard Lisp definitions of `pwd' and `cd', but
|
|
they lack somewhat in feel from the typical shell equivalents."
|
|
:tag "Directory navigation"
|
|
:group 'eshell-module))
|
|
|
|
;;; User Variables:
|
|
|
|
(defcustom eshell-dirs-load-hook nil
|
|
"A hook that gets run when `eshell-dirs' is loaded."
|
|
:version "24.1" ; removed eshell-dirs-initialize
|
|
:type 'hook
|
|
:group 'eshell-dirs)
|
|
|
|
(defcustom eshell-pwd-convert-function (if (eshell-under-windows-p)
|
|
'expand-file-name
|
|
'identity)
|
|
"The function used to normalize the value of Eshell's `pwd'.
|
|
The value returned by `pwd' is also used when recording the
|
|
last-visited directory in the last-dir-ring, so it will affect the
|
|
form of the list used by `cd ='."
|
|
:type '(radio (function-item file-truename)
|
|
(function-item expand-file-name)
|
|
(function-item identity)
|
|
(function :tag "Other"))
|
|
:group 'eshell-dirs)
|
|
|
|
(defcustom eshell-ask-to-save-last-dir 'always
|
|
"Determine if the last-dir-ring should be automatically saved.
|
|
The last-dir-ring is always preserved when exiting an Eshell buffer.
|
|
However, when Emacs is being shut down, this variable determines
|
|
whether to prompt the user, or just save the ring.
|
|
If set to nil, it means never ask whether to save the last-dir-ring.
|
|
If set to t, always ask if any Eshell buffers are open at exit time.
|
|
If set to `always', the list-dir-ring will always be saved, silently."
|
|
:type '(choice (const :tag "Never" nil)
|
|
(const :tag "Ask" t)
|
|
(const :tag "Always save" always))
|
|
:group 'eshell-dirs)
|
|
|
|
(defcustom eshell-cd-shows-directory nil
|
|
"If non-nil, using `cd' will report the directory it changes to."
|
|
:type 'boolean
|
|
:group 'eshell-dirs)
|
|
|
|
(defcustom eshell-cd-on-directory t
|
|
"If non-nil, do a cd if a directory is in command position."
|
|
:type 'boolean
|
|
:group 'eshell-dirs)
|
|
|
|
(defcustom eshell-directory-change-hook nil
|
|
"A hook to run when the current directory changes."
|
|
:type 'hook
|
|
:group 'eshell-dirs)
|
|
|
|
(defcustom eshell-list-files-after-cd nil
|
|
"If non-nil, call \"ls\" with any remaining args after doing a cd.
|
|
This is provided for convenience, since the same effect is easily
|
|
achieved by adding a function to `eshell-directory-change-hook' that
|
|
calls \"ls\" and references `eshell-last-arguments'."
|
|
:type 'boolean
|
|
:group 'eshell-dirs)
|
|
|
|
(defcustom eshell-pushd-tohome nil
|
|
"If non-nil, make pushd with no arg behave as `pushd ~' (like `cd').
|
|
This mirrors the optional behavior of tcsh."
|
|
:type 'boolean
|
|
:group 'eshell-dirs)
|
|
|
|
(defcustom eshell-pushd-dextract nil
|
|
"If non-nil, make \"pushd +n\" pop the nth dir to the stack top.
|
|
This mirrors the optional behavior of tcsh."
|
|
:type 'boolean
|
|
:group 'eshell-dirs)
|
|
|
|
(defcustom eshell-pushd-dunique nil
|
|
"If non-nil, make pushd only add unique directories to the stack.
|
|
This mirrors the optional behavior of tcsh."
|
|
:type 'boolean
|
|
:group 'eshell-dirs)
|
|
|
|
(defcustom eshell-dirtrack-verbose t
|
|
"If non-nil, show the directory stack following directory change.
|
|
This is effective only if directory tracking is enabled."
|
|
:type 'boolean
|
|
:group 'eshell-dirs)
|
|
|
|
(defcustom eshell-last-dir-ring-file-name
|
|
(expand-file-name "lastdir" eshell-directory-name)
|
|
"If non-nil, name of the file to read/write the last-dir-ring.
|
|
See also `eshell-read-last-dir-ring' and `eshell-write-last-dir-ring'.
|
|
If it is nil, the last-dir-ring will not be written to disk."
|
|
:type 'file
|
|
:group 'eshell-dirs)
|
|
|
|
(defcustom eshell-last-dir-ring-size 32
|
|
"If non-nil, the size of the directory history ring.
|
|
This ring is added to every time `cd' or `pushd' is used. It simply
|
|
stores the most recent directory locations Eshell has been in. To
|
|
return to the most recent entry, use `cd -' (equivalent to `cd -0').
|
|
To return to an older entry, use `cd -N', where N is an integer less
|
|
than `eshell-last-dir-ring-size'. To return to the last directory
|
|
matching a particular regexp, use `cd =REGEXP'. To display the
|
|
directory history list, use `cd ='.
|
|
|
|
This mechanism is very similar to that provided by `pushd', except
|
|
it's far more automatic. `pushd' allows the user to decide which
|
|
directories gets pushed, and its size is unlimited.
|
|
|
|
`eshell-last-dir-ring' is meant for users who don't use `pushd'
|
|
explicitly very much, but every once in a while would like to return to
|
|
a previously visited directory without having to type in the whole
|
|
thing again."
|
|
:type 'integer
|
|
:group 'eshell-dirs)
|
|
|
|
(defcustom eshell-last-dir-unique t
|
|
"If non-nil, `eshell-last-dir-ring' contains only unique entries."
|
|
:type 'boolean
|
|
:group 'eshell-dirs)
|
|
|
|
;;; Internal Variables:
|
|
|
|
(defvar eshell-dirstack nil
|
|
"List of directories saved by pushd in the Eshell buffer.
|
|
Thus, this does not include the current directory.")
|
|
|
|
(defvar eshell-last-dir-ring nil
|
|
"The last directory that Eshell was in.")
|
|
|
|
;;; Functions:
|
|
|
|
(defun eshell-dirs-initialize ()
|
|
"Initialize the builtin functions for Eshell."
|
|
(make-local-variable 'eshell-variable-aliases-list)
|
|
(setq eshell-variable-aliases-list
|
|
(append
|
|
eshell-variable-aliases-list
|
|
'(("-" (lambda (indices)
|
|
(if (not indices)
|
|
(unless (ring-empty-p eshell-last-dir-ring)
|
|
(expand-file-name
|
|
(ring-ref eshell-last-dir-ring 0)))
|
|
(expand-file-name
|
|
(eshell-apply-indices eshell-last-dir-ring indices)))))
|
|
("+" "PWD")
|
|
("PWD" (lambda (indices)
|
|
(expand-file-name (eshell/pwd))) t)
|
|
("OLDPWD" (lambda (indices)
|
|
(unless (ring-empty-p eshell-last-dir-ring)
|
|
(expand-file-name
|
|
(ring-ref eshell-last-dir-ring 0)))) t))))
|
|
|
|
(when eshell-cd-on-directory
|
|
(make-local-variable 'eshell-interpreter-alist)
|
|
(setq eshell-interpreter-alist
|
|
(cons (cons #'(lambda (file args)
|
|
(eshell-lone-directory-p file))
|
|
'eshell-dirs-substitute-cd)
|
|
eshell-interpreter-alist)))
|
|
|
|
(add-hook 'eshell-parse-argument-hook
|
|
'eshell-parse-user-reference nil t)
|
|
(if (eshell-under-windows-p)
|
|
(add-hook 'eshell-parse-argument-hook
|
|
'eshell-parse-drive-letter nil t))
|
|
|
|
(when (eshell-using-module 'eshell-cmpl)
|
|
(add-hook 'pcomplete-try-first-hook
|
|
'eshell-complete-user-reference nil t))
|
|
|
|
(make-local-variable 'eshell-dirstack)
|
|
(make-local-variable 'eshell-last-dir-ring)
|
|
|
|
(if eshell-last-dir-ring-file-name
|
|
(eshell-read-last-dir-ring))
|
|
(unless eshell-last-dir-ring
|
|
(setq eshell-last-dir-ring (make-ring eshell-last-dir-ring-size)))
|
|
|
|
(add-hook 'eshell-exit-hook 'eshell-write-last-dir-ring nil t)
|
|
|
|
(add-hook 'kill-emacs-hook 'eshell-save-some-last-dir))
|
|
|
|
(defun eshell-save-some-last-dir ()
|
|
"Save the list-dir-ring for any open Eshell buffers."
|
|
(dolist (buf (buffer-list))
|
|
(if (buffer-live-p buf)
|
|
(with-current-buffer buf
|
|
(if (and eshell-mode
|
|
eshell-ask-to-save-last-dir
|
|
(or (eq eshell-ask-to-save-last-dir 'always)
|
|
(y-or-n-p
|
|
(format-message
|
|
"Save last dir ring for Eshell buffer `%s'? "
|
|
(buffer-name buf)))))
|
|
(eshell-write-last-dir-ring))))))
|
|
|
|
(defun eshell-lone-directory-p (file)
|
|
"Test whether FILE is just a directory name, and not a command name."
|
|
(and (file-directory-p file)
|
|
(or (file-name-directory file)
|
|
(not (eshell-search-path file)))))
|
|
|
|
(defun eshell-dirs-substitute-cd (&rest args)
|
|
"Substitute the given command for a call to `cd' on that name."
|
|
(if (> (length args) 1)
|
|
(error "%s: command not found" (car args))
|
|
(throw 'eshell-replace-command
|
|
(eshell-parse-command "cd" (eshell-flatten-list args)))))
|
|
|
|
(defun eshell-parse-user-reference ()
|
|
"An argument beginning with ~ is a filename to be expanded."
|
|
(when (and (not eshell-current-argument)
|
|
(eq (char-after) ?~))
|
|
(add-to-list 'eshell-current-modifiers 'expand-file-name)
|
|
(forward-char)
|
|
(char-to-string (char-before))))
|
|
|
|
(defun eshell-parse-drive-letter ()
|
|
"An argument beginning with X:[^/] is a drive letter reference."
|
|
(when (and (not eshell-current-argument)
|
|
(looking-at "\\([A-Za-z]:\\)\\([^/\\\\]\\|\\'\\)"))
|
|
(goto-char (match-end 1))
|
|
(let* ((letter (match-string 1))
|
|
(regexp (concat "\\`" letter))
|
|
(path (eshell-find-previous-directory regexp)))
|
|
(concat (or path letter) "/"))))
|
|
|
|
(defvar pcomplete-stub)
|
|
(defvar pcomplete-last-completion-raw)
|
|
(declare-function pcomplete-actual-arg "pcomplete")
|
|
(declare-function pcomplete-uniqify-list "pcomplete")
|
|
|
|
(defun eshell-complete-user-reference ()
|
|
"If there is a user reference, complete it."
|
|
(let ((arg (pcomplete-actual-arg)))
|
|
(when (string-match "\\`~[a-z]*\\'" arg)
|
|
(setq pcomplete-stub (substring arg 1)
|
|
pcomplete-last-completion-raw t)
|
|
(throw 'pcomplete-completions
|
|
(progn
|
|
(eshell-read-user-names)
|
|
(pcomplete-uniqify-list
|
|
(mapcar
|
|
(function
|
|
(lambda (user)
|
|
(file-name-as-directory (cdr user))))
|
|
eshell-user-names)))))))
|
|
|
|
(defun eshell/pwd (&rest args)
|
|
"Change output from `pwd' to be cleaner."
|
|
(let* ((path default-directory)
|
|
(len (length path)))
|
|
(if (and (> len 1)
|
|
(eq (aref path (1- len)) ?/)
|
|
(not (and (eshell-under-windows-p)
|
|
(string-match "\\`[A-Za-z]:[\\\\/]\\'" path))))
|
|
(setq path (substring path 0 (1- (length path)))))
|
|
(if eshell-pwd-convert-function
|
|
(funcall eshell-pwd-convert-function path)
|
|
path)))
|
|
|
|
(defun eshell-expand-multiple-dots (path)
|
|
"Convert `...' to `../..', `....' to `../../..', etc..
|
|
|
|
With the following piece of advice, you can make this functionality
|
|
available in most of Emacs, with the exception of filename completion
|
|
in the minibuffer:
|
|
|
|
(defadvice expand-file-name
|
|
(before translate-multiple-dots
|
|
(filename &optional directory) activate)
|
|
(setq filename (eshell-expand-multiple-dots filename)))"
|
|
(while (string-match "\\(?:^\\|/\\)\\.\\.\\(\\.+\\)\\(?:$\\|/\\)" path)
|
|
(let* ((extra-dots (match-string 1 path))
|
|
(len (length extra-dots))
|
|
replace-text)
|
|
(while (> len 0)
|
|
(setq replace-text (concat replace-text "/..")
|
|
len (1- len)))
|
|
(setq path
|
|
(replace-match replace-text t t path 1))))
|
|
path)
|
|
|
|
(defun eshell-find-previous-directory (regexp)
|
|
"Find the most recent last-dir matching REGEXP."
|
|
(let ((index 0)
|
|
(len (ring-length eshell-last-dir-ring))
|
|
oldpath)
|
|
(if (> (length regexp) 0)
|
|
(while (< index len)
|
|
(setq oldpath (ring-ref eshell-last-dir-ring index))
|
|
(if (string-match regexp oldpath)
|
|
(setq index len)
|
|
(setq oldpath nil
|
|
index (1+ index)))))
|
|
oldpath))
|
|
|
|
(defun eshell/cd (&rest args) ; all but first ignored
|
|
"Alias to extend the behavior of `cd'."
|
|
(setq args (eshell-flatten-list args))
|
|
(let ((path (car args))
|
|
(subpath (car (cdr args)))
|
|
(case-fold-search (eshell-under-windows-p))
|
|
handled)
|
|
(if (numberp path)
|
|
(setq path (number-to-string path)))
|
|
(if (numberp subpath)
|
|
(setq subpath (number-to-string subpath)))
|
|
(cond
|
|
(subpath
|
|
(let ((curdir (eshell/pwd)))
|
|
(if (string-match path curdir)
|
|
(setq path (replace-match subpath nil nil curdir))
|
|
(error "Path substring `%s' not found" path))))
|
|
((and path (string-match "^-\\([0-9]*\\)$" path))
|
|
(let ((index (match-string 1 path)))
|
|
(setq path
|
|
(ring-remove eshell-last-dir-ring
|
|
(if index
|
|
(string-to-number index)
|
|
0)))))
|
|
((and path (string-match "^=\\(.*\\)$" path))
|
|
(let ((oldpath (eshell-find-previous-directory
|
|
(match-string 1 path))))
|
|
(if oldpath
|
|
(setq path oldpath)
|
|
(let ((len (ring-length eshell-last-dir-ring))
|
|
(index 0))
|
|
(if (= len 0)
|
|
(error "Directory ring empty"))
|
|
(eshell-init-print-buffer)
|
|
(while (< index len)
|
|
(eshell-buffered-print
|
|
(concat (number-to-string index) ": "
|
|
(ring-ref eshell-last-dir-ring index) "\n"))
|
|
(setq index (1+ index)))
|
|
(eshell-flush)
|
|
(setq handled t)))))
|
|
(path
|
|
(setq path (eshell-expand-multiple-dots path))))
|
|
(unless handled
|
|
(let ((curdir (eshell/pwd))
|
|
(newdir (or path "~")))
|
|
(unless (equal curdir newdir)
|
|
(eshell-add-to-dir-ring curdir))
|
|
(let ((result (cd newdir)))
|
|
(and eshell-cd-shows-directory
|
|
(eshell-printn result)))
|
|
(run-hooks 'eshell-directory-change-hook)
|
|
(if eshell-list-files-after-cd
|
|
;; Let-bind eshell-last-command around this?
|
|
(eshell-plain-command "ls" (cdr args)))
|
|
nil))))
|
|
|
|
(put 'eshell/cd 'eshell-no-numeric-conversions t)
|
|
|
|
(defun eshell-add-to-dir-ring (path)
|
|
"Add PATH to the last-dir-ring, if applicable."
|
|
(unless (and (not (ring-empty-p eshell-last-dir-ring))
|
|
(equal path (ring-ref eshell-last-dir-ring 0)))
|
|
(if eshell-last-dir-unique
|
|
(let ((index 0)
|
|
(len (ring-length eshell-last-dir-ring)))
|
|
(while (< index len)
|
|
(if (equal (ring-ref eshell-last-dir-ring index) path)
|
|
(ring-remove eshell-last-dir-ring index)
|
|
(setq index (1+ index))))))
|
|
(ring-insert eshell-last-dir-ring path)))
|
|
|
|
;;; pushd [+n | dir]
|
|
(defun eshell/pushd (&rest args) ; all but first ignored
|
|
"Implementation of pushd in Lisp."
|
|
(let ((path (car args)))
|
|
(cond
|
|
((null path)
|
|
;; no arg -- swap pwd and car of stack unless eshell-pushd-tohome
|
|
(cond (eshell-pushd-tohome
|
|
(eshell/pushd "~"))
|
|
(eshell-dirstack
|
|
(let ((old (eshell/pwd)))
|
|
(eshell/cd (car eshell-dirstack))
|
|
(setq eshell-dirstack (cons old (cdr eshell-dirstack)))
|
|
(eshell/dirs t)))
|
|
(t
|
|
(error "pushd: No other directory"))))
|
|
((string-match "^\\+\\([0-9]\\)" path)
|
|
;; pushd +n
|
|
(setq path (string-to-number (match-string 1 path)))
|
|
(cond ((> path (length eshell-dirstack))
|
|
(error "Directory stack not that deep"))
|
|
((= path 0)
|
|
(error "Couldn't cd"))
|
|
(eshell-pushd-dextract
|
|
(let ((dir (nth (1- path) eshell-dirstack)))
|
|
(eshell/popd path)
|
|
(eshell/pushd (eshell/pwd))
|
|
(eshell/cd dir)
|
|
(eshell/dirs t)))
|
|
(t
|
|
(let* ((ds (cons (eshell/pwd) eshell-dirstack))
|
|
(dslen (length ds))
|
|
(front (nthcdr path ds))
|
|
(back (nreverse (nthcdr (- dslen path) (reverse ds))))
|
|
(new-ds (append front back)))
|
|
(eshell/cd (car new-ds))
|
|
(setq eshell-dirstack (cdr new-ds))
|
|
(eshell/dirs t)))))
|
|
(t
|
|
;; pushd <dir>
|
|
(let ((old-wd (eshell/pwd)))
|
|
(eshell/cd path)
|
|
(if (or (null eshell-pushd-dunique)
|
|
(not (member old-wd eshell-dirstack)))
|
|
(setq eshell-dirstack (cons old-wd eshell-dirstack)))
|
|
(eshell/dirs t)))))
|
|
nil)
|
|
|
|
(put 'eshell/pushd 'eshell-no-numeric-conversions t)
|
|
|
|
;;; popd [+n]
|
|
(defun eshell/popd (&rest args)
|
|
"Implementation of popd in Lisp."
|
|
(let ((ref (or (car args) "+0")))
|
|
(unless (and (stringp ref)
|
|
(string-match "\\`\\([+-][0-9]+\\)\\'" ref))
|
|
(error "popd: bad arg `%s'" ref))
|
|
(setq ref (string-to-number (match-string 1 ref)))
|
|
(cond ((= ref 0)
|
|
(unless eshell-dirstack
|
|
(error "popd: Directory stack empty"))
|
|
(eshell/cd (car eshell-dirstack))
|
|
(setq eshell-dirstack (cdr eshell-dirstack))
|
|
(eshell/dirs t))
|
|
((<= (abs ref) (length eshell-dirstack))
|
|
(let* ((ds (cons nil eshell-dirstack))
|
|
(cell (nthcdr (if (> ref 0)
|
|
(1- ref)
|
|
(+ (length eshell-dirstack) ref)) ds))
|
|
(dir (cadr cell)))
|
|
(eshell/cd dir)
|
|
(setcdr cell (cdr (cdr cell)))
|
|
(setq eshell-dirstack (cdr ds))
|
|
(eshell/dirs t)))
|
|
(t
|
|
(error "Couldn't popd"))))
|
|
nil)
|
|
|
|
(put 'eshell/popd 'eshell-no-numeric-conversions t)
|
|
|
|
(defun eshell/dirs (&optional if-verbose)
|
|
"Implementation of dirs in Lisp."
|
|
(when (or (not if-verbose) eshell-dirtrack-verbose)
|
|
(let* ((msg "")
|
|
(ds (cons (eshell/pwd) eshell-dirstack))
|
|
(home (expand-file-name "~/"))
|
|
(homelen (length home)))
|
|
(while ds
|
|
(let ((dir (car ds)))
|
|
(and (>= (length dir) homelen)
|
|
(string= home (substring dir 0 homelen))
|
|
(setq dir (concat "~/" (substring dir homelen))))
|
|
(setq msg (concat msg (directory-file-name dir) " "))
|
|
(setq ds (cdr ds))))
|
|
msg)))
|
|
|
|
(defun eshell-read-last-dir-ring ()
|
|
"Set the buffer's `eshell-last-dir-ring' from a history file."
|
|
(let ((file eshell-last-dir-ring-file-name))
|
|
(cond
|
|
((or (null file)
|
|
(equal file "")
|
|
(not (file-readable-p file)))
|
|
nil)
|
|
(t
|
|
(let* ((count 0)
|
|
(size eshell-last-dir-ring-size)
|
|
(ring (make-ring size)))
|
|
(with-temp-buffer
|
|
(insert-file-contents file)
|
|
;; Save restriction in case file is already visited...
|
|
;; Watch for those date stamps in history files!
|
|
(goto-char (point-max))
|
|
(while (and (< count size)
|
|
(re-search-backward "^\\([^\n].*\\)$" nil t))
|
|
(ring-insert-at-beginning ring (match-string 1))
|
|
(setq count (1+ count)))
|
|
;; never allow the top element to equal the current
|
|
;; directory
|
|
(while (and (not (ring-empty-p ring))
|
|
(equal (ring-ref ring 0) (eshell/pwd)))
|
|
(ring-remove ring 0)))
|
|
(setq eshell-last-dir-ring ring))))))
|
|
|
|
(defun eshell-write-last-dir-ring ()
|
|
"Write the buffer's `eshell-last-dir-ring' to a history file."
|
|
(let ((file eshell-last-dir-ring-file-name))
|
|
(cond
|
|
((or (null file)
|
|
(equal file "")
|
|
(null eshell-last-dir-ring)
|
|
(ring-empty-p eshell-last-dir-ring))
|
|
nil)
|
|
((not (file-writable-p file))
|
|
(message "Cannot write last-dir-ring file %s" file))
|
|
(t
|
|
(let* ((ring eshell-last-dir-ring)
|
|
(index (ring-length ring)))
|
|
(with-temp-buffer
|
|
(while (> index 0)
|
|
(setq index (1- index))
|
|
(insert (ring-ref ring index) ?\n))
|
|
(insert (eshell/pwd) ?\n)
|
|
(eshell-with-private-file-modes
|
|
(write-region (point-min) (point-max) file nil
|
|
'no-message))))))))
|
|
|
|
(provide 'em-dirs)
|
|
|
|
;; Local Variables:
|
|
;; generated-autoload-file: "esh-groups.el"
|
|
;; End:
|
|
|
|
;;; em-dirs.el ends here
|