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 20:34:13 GMT Sender: bug-gnu-emacs-admin@gnu.org Message-ID: <14573.200211082034@altair> Reply-To: d.polani@herts.ac.uk NNTP-Posting-Host: main.gmane.org X-Trace: main.gmane.org 1036789221 7625 80.91.224.249 (8 Nov 2002 21:00:21 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Fri, 8 Nov 2002 21:00:21 +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 18AGEh-0001ya-00 for ; Fri, 08 Nov 2002 22:00:16 +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 18AGB4-0005Ot-00; Fri, 08 Nov 2002 15:56:30 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10) id 18AFsl-0006DV-00 for bug-gnu-emacs@gnu.org; Fri, 08 Nov 2002 15:37:35 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10) id 18AFs9-00061e-00 for bug-gnu-emacs@gnu.org; Fri, 08 Nov 2002 15:37:01 -0500 Original-Received: from hestia.herts.ac.uk ([147.197.200.9]) by monty-python.gnu.org with esmtp (Exim 4.10) id 18AFqK-0005Pw-00 for bug-gnu-emacs@gnu.org; Fri, 08 Nov 2002 15:35:04 -0500 Original-Received: from [147.197.200.45] (helo=altair) by hestia.herts.ac.uk with esmtp (Exim 3.22 #1) id 18AFph-0000RO-00; Fri, 08 Nov 2002 20:34:25 +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:3850 X-Report-Spam: http://spam.gmane.org/gmane.emacs.bugs:3850 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*"))))))