all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: jadamson@partners.org (Joel J. Adamson)
To: help-gnu-emacs@gnu.org
Subject: jedit.el (was: Interative batch query-replace question)
Date: Mon, 03 Dec 2007 10:32:36 -0500	[thread overview]
Message-ID: <87tzmzg5ez.fsf_-_@W0053328.mgh.harvard.edu> (raw)
In-Reply-To: m37ijx7ry7.fsf@www.luxdo.jp

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

  reply	other threads:[~2007-12-03 15:32 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-29  3:08 Interative batch query-replace question Ke Lu
2007-11-29  5:56 ` Ke Lu
2007-11-29  7:37   ` Andreas Röhler
     [not found]   ` <mailman.4291.1196321879.18990.help-gnu-emacs@gnu.org>
2007-11-29  9:15     ` Ke Lu
2007-11-29 10:18       ` Ke Lu
2007-11-29 20:55         ` Andreas Röhler
     [not found]         ` <mailman.4324.1196369791.18990.help-gnu-emacs@gnu.org>
2007-11-29 21:16           ` Joel J. Adamson
2007-11-30  1:58           ` Ke Lu
2007-11-30  8:08             ` Andreas Röhler
     [not found]             ` <mailman.4336.1196410171.18990.help-gnu-emacs@gnu.org>
2007-11-30  9:25               ` Ke Lu
2007-11-30 14:25                 ` Joel J. Adamson
2007-11-30 19:33                 ` Andreas Röhler
     [not found]                 ` <mailman.4365.1196451256.18990.help-gnu-emacs@gnu.org>
2007-12-01  1:00                   ` Ke Lu
2007-12-01  8:19                     ` Andreas Röhler
     [not found]                     ` <mailman.4382.1196497198.18990.help-gnu-emacs@gnu.org>
2007-12-01  9:11                       ` Ke Lu
2007-12-01 15:19                         ` Xah Lee
2007-12-02  2:16                           ` Ke Lu
2007-12-03 15:27                             ` Joel J. Adamson
2007-12-01 17:39                         ` Andreas Röhler
     [not found]                         ` <mailman.4401.1196530793.18990.help-gnu-emacs@gnu.org>
2007-12-02  2:26                           ` Ke Lu
2007-12-03 15:32                             ` Joel J. Adamson [this message]
2007-11-29  6:54 ` Andreas Röhler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87tzmzg5ez.fsf_-_@W0053328.mgh.harvard.edu \
    --to=jadamson@partners.org \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.