[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: simple useful functions
From: |
Andreas Röhler |
Subject: |
Re: simple useful functions |
Date: |
Tue, 02 Nov 2010 08:27:59 +0100 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; de; rv:1.9.1.11) Gecko/20100711 Thunderbird/3.0.6 |
Am 28.10.2010 20:56, schrieb Tak Ota:
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)))))
Hi Tak,
thanks a lot.
Took your stuff into my personal collection misc-utils.el at
https://code.launchpad.net/s-x-emacs-werkstatt/
also into a git-repo collecting interesting stuff
http://repo.or.cz/w/elbb.git
Andreas
--
https://code.launchpad.net/~a-roehler/python-mode/python-mode-components
- Re: simple useful functions, (continued)
- Re: simple useful functions, Tak Ota, 2010/11/03
- collect-string (was: simple useful functions), Stefan Monnier, 2010/11/04
- Re: collect-string (was: simple useful functions), Tak Ota, 2010/11/04
- Re: collect-string (was: simple useful functions), Tak Ota, 2010/11/04
- Re: collect-string (was: simple useful functions), Tak Ota, 2010/11/04
- Re: collect-string (was: simple useful functions), Andreas Röhler, 2010/11/05
- Re: collect-string, Stefan Monnier, 2010/11/08
- Re: collect-string, Tak Ota, 2010/11/08
- Re: collect-string, Stephen J. Turnbull, 2010/11/09
- Re: collect-string, Tak Ota, 2010/11/09
Re: simple useful functions,
Andreas Röhler <=