From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Daniel Polani Newsgroups: gmane.emacs.bugs Subject: Suggestion for new emacs functionality Date: Fri, 8 Nov 2002 21:50:21 GMT Sender: bug-gnu-emacs-admin@gnu.org Message-ID: <15847.200211082150@altair> Reply-To: d.polani@herts.ac.uk NNTP-Posting-Host: main.gmane.org X-Trace: main.gmane.org 1036793804 26454 80.91.224.249 (8 Nov 2002 22:16:44 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Fri, 8 Nov 2002 22:16:44 +0000 (UTC) Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 18AHQh-0006sW-00 for ; Fri, 08 Nov 2002 23:16:43 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10) id 18AHR4-0007Cd-00; Fri, 08 Nov 2002 17:17:06 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10) id 18AHDo-0005SR-00 for bug-gnu-emacs@gnu.org; Fri, 08 Nov 2002 17:03:24 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10) id 18AH1s-0000uj-00 for bug-gnu-emacs@gnu.org; Fri, 08 Nov 2002 16:51:06 -0500 Original-Received: from hestia.herts.ac.uk ([147.197.200.9]) by monty-python.gnu.org with esmtp (Exim 4.10) id 18AH1r-0000tv-00 for bug-gnu-emacs@gnu.org; Fri, 08 Nov 2002 16:51:03 -0500 Original-Received: from [147.197.200.45] (helo=altair) by hestia.herts.ac.uk with esmtp (Exim 3.22 #1) id 18AH1D-00064I-00; Fri, 08 Nov 2002 21:50:23 +0000 Original-To: bug-gnu-emacs@gnu.org X-MailScanner: No Virus detected Errors-To: bug-gnu-emacs-admin@gnu.org X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Bug reports for GNU Emacs, the Swiss army knife of text editors List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.bugs:3851 X-Report-Spam: http://spam.gmane.org/gmane.emacs.bugs:3851 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*"))))))