From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: jadamson@partners.org (Joel J. Adamson) Newsgroups: gmane.emacs.help Subject: jedit.el (was: Interative batch query-replace question) Date: Mon, 03 Dec 2007 10:32:36 -0500 Organization: I need to put my ORGANIZATION here. Message-ID: <87tzmzg5ez.fsf_-_@W0053328.mgh.harvard.edu> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1196696558 32742 80.91.229.12 (3 Dec 2007 15:42:38 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 3 Dec 2007 15:42:38 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Dec 03 16:42:47 2007 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1IzDRW-0001M5-0V for geh-help-gnu-emacs@m.gmane.org; Mon, 03 Dec 2007 16:42:46 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IzDRF-0005Kp-OR for geh-help-gnu-emacs@m.gmane.org; Mon, 03 Dec 2007 10:42:29 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!postnews.google.com!news2.google.com!news.glorb.com!newspeer1.asbnva01.us.to.verio.net!news.harvard.edu!not-for-mail Original-Newsgroups: gnu.emacs.help,gnu.emacs.sources Original-Lines: 90 Original-NNTP-Posting-Host: w0053328.mgh.harvard.edu Original-X-Trace: plato.harvard.edu 1196695963 13527 132.183.29.121 (3 Dec 2007 15:32:43 GMT) Original-X-Complaints-To: news@plato.harvard.edu Original-NNTP-Posting-Date: Mon, 3 Dec 2007 15:32:43 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) Cancel-Lock: sha1:tHWniz5tiMsuatR60RsKnWEXO5k= Original-Xref: shelby.stanford.edu gnu.emacs.help:154365 gnu.emacs.sources:12424 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:49792 Archived-At: Some custom editing functions: suggestions welcome. ;;; jedit.el --- Joel's Custom Editing Functions ;; Author: Joel J. Adamson ;; Maintainer: Joel J. Adamson ;; version 0.1 ;; keywords: tex matching ;; Copyright (C) 2007 Joel J. Adamson ;; 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; either version 3 of ;; the License, or (at your option) any later version. ;; 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. ;; You should have received a copy of the GNU General Public ;; License along with this program; if not, write to the Free ;; Software Foundation, Inc., 51 Franklin Street, Fifth Floor, ;; Boston, MA 02110-1301 USA ;;; Code: ;; strip unrecognized regexes from latex files for latex2rtf (defun jedit-strip-regex (alist) "Takes a list of regex-replacement string pairs; processes entire buffer." (interactive "sList: ") ;; for each cell in alist, define regex and replacement text (dolist (regex-cell alist) (let ((regex (car regex-cell)) (replacement (cadr regex-cell))) ;; go to beginning of buffer (goto-char (point-min)) ;; when you find the search string, replace it with replacement ;; text (while (re-search-forward regex nil t) (replace-match replacement nil nil))))) ;; tex-insert-file ;; takes an input command and inserts the file ;; directly into the current buffer (defun jedit-tex-insert-file (&optional buffer) "Find a .tex file and insert it into a buffer at \input{`filename'}; `filename' is found automatically from \input command by searching for a `filename' as a blank text file and then for `filename'.tex" ;; enter a buffer name; defaults to (current-buffer) (interactive "bBuffer: ") ;; return to the beginning of buffer (goto-char (point-min)) ;; set the symbol filename to be nothing, incase it already exists (setq filename "") ;; every time you find an \input{`filename'} command, (let ((count 0)) (while (and (< (point) (point-max)) (re-search-forward "\\\\input{\\(.*?\\)}" nil t)) (setq count (1+ count)) ;; search for the file first as `filename' (a plain text file) (let ((txt-filename (match-string-no-properties 1)) ;; and then as a TeX file with a .tex extension (tex-filename (concat (match-string-no-properties 1) ".tex"))) (when (cond ((file-readable-p txt-filename) (setq filename txt-filename)) ((file-readable-p tex-filename) (setq filename tex-filename)) ;; if the file can't be found within these ;; parameters, exit with an error (t (error "tex-insert-file Error: no %s or %s found" txt-filename tex-filename))) ;; remove the entire matched string (replace-match "") ;; insert the file contents into the current-buffer (insert-file-contents filename))) ;; output messages for user (cond ((zerop count) (message "No replacements")) ((= 1 count) (message "Made 1 replacement")) (t (message "Made %d replacements" count)))))) (provide 'jedit) (require 'jedit) ;;; jedit.el ends here