[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
simple useful functions
From: |
Tak Ota |
Subject: |
simple useful functions |
Date: |
Thu, 28 Oct 2010 11:56:15 -0700 |
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)))))
- simple useful functions,
Tak Ota <=
- simple useful functions, Stephen J. Turnbull, 2010/10/29
- Re: simple useful functions, Tak Ota, 2010/10/29
- RE: simple useful functions, Drew Adams, 2010/10/29
- Re: simple useful functions, Andreas Schwab, 2010/10/29
- RE: simple useful functions, Drew Adams, 2010/10/29
- Re: simple useful functions, Andreas Schwab, 2010/10/29
- Re: simple useful functions, Chad Brown, 2010/10/29
- RE: simple useful functions, Drew Adams, 2010/10/29
- RE: simple useful functions, Stephen J. Turnbull, 2010/10/30
- Re: simple useful functions, Thierry Volpiatto, 2010/10/30