From e7e076d41091098706c4a0aa9a0df851eea62a5d Mon Sep 17 00:00:00 2001 From: Andreas Roehler Date: Tue, 2 Nov 2010 08:12:16 +0100 Subject: [PATCH] simple useful functions from Tak Ota --- code/elbb.el | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/code/elbb.el b/code/elbb.el index 4e16127..efb5574 100644 --- a/code/elbb.el +++ b/code/elbb.el @@ -1,3 +1,54 @@ +* Simple useful functions + +Date: Thu, 28 Oct 2010 11:56:15 -0700 +From: Tak Ota +To: +Subject: simple useful functions +Envelope-To: andreas.roehler@online.de + +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))))) + * How highlight 16 or more occurrences of same character? To: help-gnu-emacs@gnu.org -- 2.11.4.GIT