From: Daniel Polani <d.polani@herts.ac.uk>
Subject: Suggestion for new emacs functionality
Date: Fri, 8 Nov 2002 20:34:13 GMT [thread overview]
Message-ID: <14573.200211082034@altair> (raw)
Hello all,
I would like to submit two new functionalities for either inclusion in
the standard emacs distribution or as extra package (which, however, I
would not believe would make sense, as they are quite small).
I found both functions extremely useful and use them often. I am happy
to transfer the copyright to the FSF if a standard inclusion into the
emacs distribution is planned. Alternatively I would release them
under the GPL.
I posted shell-current-directory many years ago into the emacs.sources
newsgroup and did never get a reaction until several years later, when
somebody actually gave feedback and mentioned that he was using it all
the time. So, I believe, it is a useful command.
Please let me know if there is any open question or request. Please
note that I have no access to the emacs newsgroups at my present
location, so if you wish to contact me, please send me a direct mail.
--
Daniel Polani
| Dept of Computer Science | Tel. +44/1707/28 4380 |
| University of Hertfordshire | Fax: +44/1707/28 4303 |
| Hatfield, Herts AL10 9AB | |
| United Kingdom | |
-------------------------------------------------------------------
| Web: http://homepages.feis.herts.ac.uk/~comqdp1/ |
;;; write-file-from-buffer
;;; write-file-from-buffer, is useful if you have
;;; loaded a file from some directory, say 'A' into an emacs buffer. If
;;; your current buffer has default directory 'B' (e.g. it can be an
;;; dired-buffer), then you can use M-x write-file-from-buffer to write an
;;; existing buffer content into the present directory. This saves you
;;; looking for the original file and/or directory.
(defun write-file-from-buffer (buf)
"Write BUFFER to file with same name of visited file to current directory.
Current directory is given by current buffer."
(interactive "b")
(save-excursion
(let ((dir default-directory))
(set-buffer buf)
(write-file dir t))))
;;; shell-current-directory
;;; shell-current-directory works like the command called via M-x shell
;;; with the difference that a shell is started using the current default
;;; directory and a new shell is started in each new directory.
(defun directory-shell-buffer-name ()
"The name of a shell buffer pertaining to DIR."
(concat "*"
(file-name-nondirectory
(directory-file-name (expand-file-name default-directory)))
"-shell*"))
(defun directory-shell-buffer ()
"Return a buffer with the current default directory shell process."
(let ((buflist (buffer-list))
found
buffer
buffer-directory
bufproc
retval)
(while (and (not found) buflist)
(setq buffer (pop buflist))
(setq buffer-directory
(save-excursion
(set-buffer buffer)
default-directory))
(setq bufproc (get-buffer-process buffer))
(if bufproc
(if (and (string-match "^shell\\(<[0-9]*>\\)?$"
(process-name bufproc))
(string= default-directory buffer-directory))
(setq found t))))
(if found
buffer
nil)))
(defun shell-current-directory ()
"Create a shell pertaining to the current directory."
(interactive)
(let ((current-shell-buffer (directory-shell-buffer))
original-shell-buffer)
(if current-shell-buffer
(pop-to-buffer current-shell-buffer)
;; no current process buffer is active
;; if *shell* is already used, store it
(if (buffer-live-p "*shell*")
(save-excursion
(set-buffer "*shell*")
(setq original-shell-buffer (rename-uniquely))))
;; and create a new shell process with the current directory
(shell)
(rename-buffer (directory-shell-buffer-name) t) ; unique
(if original-shell-buffer ; there has been a standard
; *shell* buffer before,
; restore it
(save-excursion
(set-buffer original-shell-buffer)
(rename-buffer "*shell*"))))))
next reply other threads:[~2002-11-08 20:34 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-11-08 20:34 Daniel Polani [this message]
-- strict thread matches above, loose matches on Subject: below --
2002-11-08 21:50 Suggestion for new emacs functionality Daniel Polani
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=14573.200211082034@altair \
--to=d.polani@herts.ac.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).