🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: gnu.emacs.sources
4 messages
4 total messages Started by Matt Conway Sun, 20 Dec 1992 05:49
REQUEST: find-multiple-buffers.el
#297
Author: Matt Conway
Date: Sun, 20 Dec 1992 05:49
18 lines
1248 bytes
I'm looking for a function that I think is called
find-multiple-buffers.el. It allows a user to do a find-file on a
regular expression (to load all *.C files, for example.).

Is there anyone here who knows where to find this function, or one
that does what I'm describing? 

				thanks, 	
				Matt
-- 
----------------------------------------------------------------------
Matthew Conway              | HA! ...(pronoun trouble)...It's not, 
University of Virginia      | 'He doesn't have to shoot *you*
Dept. of Computer Science   | now,' it's, 'He doesn't have to shoot
Charlottesville, VA 22901   | *me* now.'  Well, I say he DOES have
mjc4y@uvacs.cs.virginia.edu | to shoot me now!  So SHOOT ME NOW!!
----------------------------------------------------------------------
Re: REQUEST: find-multiple-buffers.el
#298
Author: Scott Draves
Date: Sun, 20 Dec 1992 19:07
34 lines
1998 bytes
oops, sorry, i forgot the support functions.  btw, i didn't write this
code, but i don't know who did.  it's been in my .emacs for years...

(defun csh-re-to-regexp (reg)
  "Convert a C-shell regular expression to a true r.e."
  (concat "^" (mapconcat 'convert-csh-re-to-regexp reg "") "$"))

(defun convert-csh-re-to-regexp (ch)
  "Convert a C-shell wildcard to its regular expression counterpart"
  (cond ((equal ch ?.) "\\.")
        ((equal ch ?*) ".*")
        ((equal ch ??) ".")
        (t (char-to-string ch))))

;;; should derive default RE from mode-alist
(defun find-regexp-files (prefix dir reg)
  "Prompt for a directory and a regular expression.  Open 
buffers for all the files matching that regular expression in the
directory.  The default RE is *.{c,h,y,l,sml,sig}."
  (interactive "p\nDDirectory: \nsRegexp: ")
  (if (equal reg "")
      (setq reg ".*\\.\\(c\\|h\\|y\\|l\\|sml\\|sig\\)$")
    (if (equal prefix 1)
	(setq reg (csh-re-to-regexp reg))))
  (setq files (directory-files dir t reg))
  (if (not files)
      (message "no matching files"))
  (while files
    (find-file (car files))
    (setq files (cdr files))))
-- 
				orgasm
Scott Draves			nitrous
spot@cs.cmu.edu			death
Re: REQUEST: find-multiple-buffers.el
#246
Author: T. V. Raman
Date: Mon, 21 Dec 1992 14:00
22 lines
1458 bytes

In general the cleaner solution to open a bunch of related files is to
run etags on the files, visit the tags table, and let emacs open the
necessary files for you.

This is a far more efficient way of locating and jumping to a
particular function definition in a collection of C files compared to
opening all the files together in EMACS. The same applies to TeX files
etc.

A program called petags was posted on this group a while ago that
extends etags functionality to syntax not recognized by etags, so
unless you have some other reason to want to open a bunch of files in
Emacs using regexps (I don't see any)  you should probably use tags.

--Raman
-- 
   T. V. Raman <raman@cs.cornell.edu>Tel: (607)255-9202  R 272-3649
                       Office: 4116 Upson Hall,
Department of Computer Science, Cornell University Ithaca NY 14853-6201
                Res: 226 Bryant Avenue Ithaca NY 14850
Re: REQUEST: find-multiple-buffers.el
#250
Author: Lars Bo Nielsen
Date: Wed, 23 Dec 1992 08:45
224 lines
8588 bytes
In article <1992Dec20.054956.24937@murdoch.acc.Virginia.EDU> mjc4y@uvacs.cs.Virginia.EDU (Matt Conway) writes:
   I'm looking for a function that I think is called
   find-multiple-buffers.el. It allows a user to do a find-file on a
   regular expression (to load all *.C files, for example.).

   Is there anyone here who knows where to find this function, or one
   that does what I'm describing? 

I have some old code laying around that probably does what you are
looking for.  Using this you do not have to quit your current emacs
just to say:

	emacs *.c *.h

when you want to change something in all your source files.  Just
call `re-find-file'. It will prompt for a directory (default current).
and then let you specify a regular expression that the files you are
going to load would match - you will even see which files match the
regular expression. In the previous example you would just enter:

	\.[ch]$

to get the *.c and *.h files.

When you have finished editing, the function `re-remove-buffers' will
remove all the buffers that was loaded in the previous call to
`re-find-file'.

Hope this will do the job,

Merry Christmas and a Happy New Year,

Lars Bo Nielsen (lbn@hugin.dk)

----cut here----cut here----cut here----cut here----cut here----
;; 
;; find-files.el - Find files matching reg-exp
;; 
;; Copyright (C) 1990 Lars Bo Nielsen (lbn@iesd.auc.dk).
;; 
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation.
;; 
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
;; See the GNU General Public License for more details.
;; 
;; Author          : Lars Bo Nielsen
;; Created On      : Wed Jan 17 14:31:31 1990
;; Last Modified By: Lars Bo Nielsen
;; Last Modified On: Tue Mar 27 18:59:25 1990
;; Update Count    : 66
;; 
;; HISTORY
;; 27-Mar-1990  (Last Mod: Wed Jan 24 15:17:22 1990 #65)  Lars Bo Nielsen
;;    're-find-file-display' has been changed to 'insert-list'
;; 19-Jan-1990  (Last Mod: Fri Jan 19 14:59:41 1990 #58)  Lars Bo Nielsen
;;    Added 're-remove-buffers' to remove the buffers. They are listed
;;    in 're-find-file-alist'.
;;    Also the function 're-find-file-display' has been added.
;; 19-Jan-1990  (Last Mod: Fri Jan 19 11:21:56 1990 #52)  Lars Bo Nielsen
;;    Reading '%' caused a bug, now two is inserted, and deleted.
;; 19-Jan-1990  (Last Mod: Fri Jan 19 09:00:29 1990 #40)  Lars Bo Nielsen
;;    Inhibit ^G inside the function. We catch it and kill the local
;;    buffers.
;;    I don't know how the normal keyboard commands (like ^X^B) is
;;    supposed to be catched.
;; 18-Jan-1990  (Last Mod: Thu Jan 18 20:35:05 1990 #35)  Lars Bo Nielsen
;;    Now it should be ok.
;; 

(defconst re-find-file-alist nil
  "List of files found by resent success-full call to re-find-file.")

(defun re-find-file (directory)
  (interactive "DFrom directory : ")
  (let ((tmp-buf (generate-new-buffer " * re-find-file tmp-buffer * "))
	(savedconfig (current-window-configuration))
	(list nil)
	(match-list nil)
	(regexp-not-complete t)
	(reg-exp-ok t)
	(regexp-complain "")
	(inhibit-quit t)
	(match "")
	(cur-buffer (current-buffer))
	char
	complete-buf)
    (or (string-match "/$" directory)
	(setq directory (concat directory "/")))
    (setq complete-buf directory)
    (set-buffer tmp-buf)		; Output goes to tmp-buf
    (erase-buffer)			; erase it
    (call-process "ls" nil t nil "-1A" (expand-file-name directory))
    (goto-char (point-min))		; Goto beginning of tmp-buf
    (while (not (eobp))
      (setq list
	    (cons (buffer-substring (point) (progn (end-of-line) (point)))
		  list))
      (or (eobp) (forward-char 1)))
    (switch-to-buffer complete-buf)
    (delete-other-windows)
    (while regexp-not-complete
      (if reg-exp-ok
	  (let ((tmp-list list))
	    (setq match-list nil)
	    (erase-buffer)
	    (while tmp-list
	      (if (or (string-match match (car tmp-list))
		      (string= ""  match))
		  (setq match-list (cons (car tmp-list) match-list)))
	      (setq tmp-list (cdr tmp-list)))
	    (erase-buffer)
	    (insert-list match-list)))
      (message (concat (format "%s file%s matching : "
			       (if (eq (length match-list) 0) "No"
				 (length match-list))
			       (if (eq (length match-list) 1) "" "s"))
		       match regexp-complain))
      (setq char (read-char))
      (cond
       ((eq char ?\C-g)			; Just exit
	(message "")
	(kill-buffer complete-buf)
	(kill-buffer tmp-buf)
	(set-window-configuration savedconfig)
	(signal 'quit nil))
       ((eq char ?\C-?)			; Delete last char
	(if (eq (length match) 0)	; Test if there is anything
	    (beep)			; to delete
	  (if (string-match "%%$" match) ; Extra care with '%'
	      (setq match (substring match 0 (- (length match) 2)))
	    (setq match (substring match 0 (1- (length match)))))))
       ((eq char ?\C-M)			; Return was pressed
	(setq regexp-not-complete nil))
       ((eq char ?%)			; Extra care with '%'
	(setq match (concat match "%%")))
       (t (setq match (concat match (char-to-string char)))))
      (condition-case errorval
	  (progn			; Test regexp
	    (looking-at match)		
	    (setq reg-exp-ok t regexp-complain ""))
	(error (progn (setq regexp-complain " [Incomplete input]")
		      (setq regexp-not-complete t)
		      (setq reg-exp-ok nil)))))
    (setq re-find-file-alist match-list)
    (setq inhibit-quit nil)
    (condition-case ()
	(if (and match-list (yes-or-no-p "Find files? "))
	    (progn
	      (while match-list
		(let* ((inhibit-quit nil) ; Allow quitting in here
		       (filename (car match-list))
		       (filefullname (concat directory filename)))
		  (if (file-directory-p filefullname)
		      (progn
			(beep)
			(if (y-or-n-p
			     (concat "File \"" filename
				     "\" is a directory. Read : "))
			    (progn
			      (message (concat "Getting " filename " ..."))
			      (find-file filefullname))))
		    (message (concat "Getting " filename " ..."))
		    (find-file filefullname)))
		(setq match-list (cdr match-list)))
	      (kill-buffer complete-buf)
	      (kill-buffer tmp-buf))
	  (message "")
	  (kill-buffer complete-buf)
	  (kill-buffer tmp-buf)
	  (set-window-configuration savedconfig))
      (quit (progn
	      (beep)
	      (kill-buffer complete-buf)
	      (kill-buffer tmp-buf)
	      (set-window-configuration savedconfig))))))

(defun re-remove-buffers ()
  (interactive)
  (let ((buffer (get-buffer-create " *temp*"))
	(list re-find-file-alist)
	(cur-win (current-window-configuration)))
    (if re-find-file-alist
	(progn
	  (switch-to-buffer buffer)
	  (delete-other-windows)
	  (unwind-protect
	      (progn
		(insert-list re-find-file-alist)
		(if (yes-or-no-p "Delete buffers? ")
		    (progn
		      (message "Deleting buffers ...")
		      (while list
			(condition-case ()
			    (kill-buffer (car list))
			  (error ()))
			(setq list (cdr list)))
		      (setq re-find-file-alist nil)
		      (message "Deleting buffers ... done"))))
	    (progn
	      (kill-buffer buffer)
	      (set-window-configuration cur-win))))
      (kill-buffer buffer)
      (error "No buffers to delete"))))

(defun insert-list (list &optional cols)
  "Inserts, in current buffer, LIST in cols.
Optional second arg COLS, default coloums.
If second arg not supplied, as many colums as possible is made."
  (let ((maxsize (if cols
		     (/ 80 cols)
		   (+ 2 (apply 'max (cons 10 (mapcar 'length list)))))))
    (while list
      (insert (car list))
      (insert-char ?\  (- maxsize (length (car list))))
      (if (> (current-column) (- 80 maxsize))
	  (progn
	    (just-one-space)
	    (insert "\n")))
      (setq list (cdr list)))
    (goto-char (point-min))))
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads