unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* simple useful functions
@ 2010-10-28 18:56 Tak Ota
  2010-10-29  3:39 ` Stephen J. Turnbull
                   ` (3 more replies)
  0 siblings, 4 replies; 58+ messages in thread
From: Tak Ota @ 2010-10-28 18:56 UTC (permalink / raw)
  To: emacs-devel

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)))))




^ permalink raw reply	[flat|nested] 58+ messages in thread

end of thread, other threads:[~2010-12-07  3:24 UTC | newest]

Thread overview: 58+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-28 18:56 simple useful functions Tak Ota
2010-10-29  3:39 ` Stephen J. Turnbull
2010-10-29 18:13   ` Tak Ota
2010-10-29 19:02     ` Drew Adams
2010-10-29 19:26       ` Andreas Schwab
2010-10-29 20:19         ` Drew Adams
2010-10-29 20:47           ` Andreas Schwab
2010-10-29 20:56             ` Chad Brown
2010-10-29 21:23               ` Drew Adams
2010-10-30  9:01       ` Stephen J. Turnbull
2010-10-30 10:55     ` Thierry Volpiatto
2010-11-02  0:40     ` Tak Ota
2010-11-02  2:22       ` Stephen J. Turnbull
2010-11-03  0:38         ` Tak Ota
2010-11-03  5:27           ` Stephen J. Turnbull
2010-11-03  8:09             ` Andreas Röhler
2010-11-03 10:13               ` Stephen J. Turnbull
2010-11-03 18:08                 ` Tak Ota
2010-11-03 18:01             ` Tak Ota
2010-11-04  2:10               ` Stephen J. Turnbull
2010-11-04  2:20                 ` Tak Ota
2010-11-04 13:58                 ` collect-string (was: simple useful functions) Stefan Monnier
2010-11-04 18:36                   ` Tak Ota
2010-11-04 20:18                     ` Tak Ota
2010-11-04 20:27                       ` Tak Ota
2010-11-05  7:52                         ` Andreas Röhler
2010-11-08 18:36                     ` collect-string Stefan Monnier
2010-11-09  0:18                       ` collect-string Tak Ota
2010-11-09  9:06                         ` collect-string Stephen J. Turnbull
2010-11-10  2:12                       ` collect-string Tak Ota
2010-11-30  2:14                         ` collect-string Tak Ota
2010-11-30  5:27                           ` collect-string Stephen J. Turnbull
2010-12-02  1:59                             ` collect-string Tak Ota
2010-12-02  7:00                               ` collect-string Stephen J. Turnbull
2010-12-02 14:16                         ` collect-string Stefan Monnier
2010-12-03  1:03                           ` collect-string Tak Ota
2010-12-03 19:17                             ` collect-string Stefan Monnier
2010-12-03 22:31                               ` collect-string Tak Ota
2010-12-03 22:40                                 ` collect-string Davis Herring
2010-12-03 22:47                                   ` collect-string Tak Ota
2010-12-03 22:56                                 ` collect-string Stefan Monnier
2010-12-03 23:15                                   ` collect-string Tak Ota
2010-12-04  2:01                                     ` collect-string Stefan Monnier
2010-12-04  2:07                                       ` collect-string Tak Ota
2010-12-04  3:27                                   ` collect-string Glenn Morris
2010-10-29  8:44 ` simple useful functions Andreas Schwab
2010-11-02  7:27 ` Andreas Röhler
2010-12-03 23:37 ` Tak Ota
2010-12-04  2:36   ` Stefan Monnier
2010-12-04  2:58     ` Tak Ota
2010-12-04  4:36       ` Stefan Monnier
2010-12-04  9:10         ` David Kastrup
2010-12-06 14:08         ` René Kyllingstad
2010-12-06 19:31           ` Stefan Monnier
2010-12-06 18:39         ` Tak Ota
2010-12-06 20:23           ` Stefan Monnier
2010-12-06 21:25             ` Tak Ota
2010-12-07  3:24               ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).