[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: simple useful functions
From: |
Tak Ota |
Subject: |
Re: simple useful functions |
Date: |
Fri, 3 Dec 2010 15:37:10 -0800 |
Now `collect-string' seems to have found an appropriate place to fit
in `occur' can we revisit `source' command? It would be useful if
this is a part of shell.el or somewhere with more appropriate name.
-Tak
Thu, 28 Oct 2010 11:56:15 -0700: Tak Ota <address@hidden> wrote:
> If you think the following two functions are universally useful please
> consider incorporating them in simple.el or any appropriate package.
> If not disregard.
>
> -Tak
>
> (defun collect-string (regexp &optional num)
> "Collect strings of REGEXP (or optional NUM paren) from the
> current buffer into a collection buffer."
> (interactive "sCollect string (regexp): \nP")
> (let ((collection-buffer
> (get-buffer-create (format "*Collection of \"%s\" *" regexp))))
> (with-current-buffer collection-buffer (erase-buffer))
> (save-excursion
> (goto-char (point-min))
> (while (re-search-forward regexp nil t)
> (let ((str (match-string (or num 0))))
> (if str
> (with-current-buffer collection-buffer
> (insert str)
> (or (zerop (current-column))
> (insert "\n")))))))
> (pop-to-buffer collection-buffer)
> (goto-char (point-min))))
>
> (defun source (script &optional shell keep-current-directory)
> "Source the specified shell script.
> Source the shell SCRIPT and import the environment into this
> emacs. The optional SHELL specifies the shell other than the
> default `shell-file-name'. When KEEP-CURRENT-DIRECTORY is nil,
> which is the default, the current directory is temporarily
> changed to the directory where the script resides while sourcing
> the script."
> (interactive "fscript file: ")
> (if (null shell)
> (setq shell shell-file-name))
> (with-temp-buffer
> (unless keep-current-directory
> (setq default-directory (file-name-directory script)))
> (call-process shell nil t nil "-c" (concat "source " script "; printenv"))
> (while (re-search-backward "^\\([^=]+\\)=\\(.*\\)$" nil t)
> (setenv (match-string 1) (match-string 2)))))
- Re: simple useful functions,
Tak Ota <=
- Re: simple useful functions, Stefan Monnier, 2010/12/03
- Re: simple useful functions, Tak Ota, 2010/12/03
- Re: simple useful functions, Stefan Monnier, 2010/12/03
- Re: simple useful functions, David Kastrup, 2010/12/04
- Re: simple useful functions, Tak Ota, 2010/12/06
- Re: simple useful functions, Stefan Monnier, 2010/12/06
- Re: simple useful functions, Tak Ota, 2010/12/06
- Re: simple useful functions, Stefan Monnier, 2010/12/06
- Re: simple useful functions, René Kyllingstad, 2010/12/06
- Re: simple useful functions, Stefan Monnier, 2010/12/06