emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Uwe Brauer <oub@mat.ucm.es>
To: nicholas.dokos@hp.com
Cc: emacs-orgmode@gnu.org
Subject: solved; sort of (was: Bug: can't export org file with tables to html [7.01trans])
Date: Wed, 27 Oct 2010 17:24:24 +0200	[thread overview]
Message-ID: <878w1jzmjb.fsf_-_@gilgamesch.quim.ucm.es> (raw)
In-Reply-To: <29281.1288189800@gamaville.dokosmarshall.org> (Nick Dokos's message of "Wed, 27 Oct 2010 10:30:00 -0400")

>> Regarding Re: [Orgmode] Bug: can't export org file with tables to html [7.01trans]; Nick Dokos <nicholas.dokos@hp.com> adds:

   >> 

   > C-h v replace-regexp-in-string says (among other things):

I just copied the function from Xemacs 21.5 and then the
export functions works again.

Carsten, may I ask you to include this function, maybe we
should have a xemacs-21.4-compat.el file?

thanks

Uwe 



(defun replace-regexp-in-string (regexp rep string &optional
					fixedcase literal subexp start)
  "Replace all matches for REGEXP with REP in STRING.

Return a new string containing the replacements.

Optional arguments FIXEDCASE and LITERAL are like the arguments with
the same names of function `replace-match'.  If START is non-nil,
start replacements at that index in STRING.

For compatibility with old XEmacs code and with recent GNU Emacs, the
interpretation of SUBEXP is somewhat complicated.  If SUBEXP is a
buffer, it is interpreted as the buffer which provides syntax tables
and case tables for the match and replacement.  If it is not a buffer,
the current buffer is used.  If SUBEXP is an integer, it is the index
of the subexpression of REGEXP which is to be replaced.

REP is either a string used as the NEWTEXT arg of `replace-match' or a
function.  If it is a function it is applied to each match to generate
the replacement passed to `replace-match'; the match-data at this
point are such that `(match-string SUBEXP STRING)' is the function's
argument if SUBEXP is an integer \(otherwise the whole match is passed
and replaced).

To replace only the first match (if any), make REGEXP match up to \\'
and replace a sub-expression, e.g.
  (replace-regexp-in-string \"\\(foo\\).*\\'\" \"bar\" \" foo foo\" nil nil 1)
    => \" bar foo\"

Signals `invalid-argument' if SUBEXP is not an integer, buffer, or nil;
or is an integer, but the indicated subexpression was not matched.
Signals `invalid-argument' if STRING is nil but the last text matched was a string,
or if STRING is a string but the last text matched was a buffer."

  ;; To avoid excessive consing from multiple matches in long strings,
  ;; don't just call `replace-match' continually.  Walk down the
  ;; string looking for matches of REGEXP and building up a (reversed)
  ;; list MATCHES.  This comprises segments of STRING which weren't
  ;; matched interspersed with replacements for segments that were.
  ;; [For a `large' number of replacments it's more efficient to
  ;; operate in a temporary buffer; we can't tell from the function's
  ;; args whether to choose the buffer-based implementation, though it
  ;; might be reasonable to do so for long enough STRING.]
  (let ((l (length string))
	(start (or start 0))
	(expndx (if (integerp subexp) subexp 0))
	matches str mb me)
    (save-match-data
      (while (and (< start l) (string-match regexp string start))
	(setq mb (match-beginning 0)
	      me (match-end 0))
	;; If we matched the empty string, make sure we advance by one char
	(when (= me mb) (setq me (min l (1+ mb))))
	;; Generate a replacement for the matched substring.
	;; Operate only on the substring to minimize string consing.
	;; Set up match data for the substring for replacement;
	;; presumably this is likely to be faster than munging the
	;; match data directly in Lisp.
	(string-match regexp (setq str (substring string mb me)))
	(setq matches
	      (cons (replace-match (if (stringp rep)
				       rep
				     (funcall rep (match-string expndx str)))
				   ;; no, this subexp shouldn't be expndx
				   fixedcase literal str subexp)
		    (cons (substring string start mb) ; unmatched prefix
			  matches)))
	(setq start me))
      ;; Reconstruct a string from the pieces.
      (setq matches (cons (substring string start l) matches)) ; leftover
      (apply #'concat (nreverse matches)))))

  parent reply	other threads:[~2010-10-27 15:26 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-27 13:29 Bug: can't export org file with tables to html [7.01trans] Uwe Brauer
2010-10-27 13:48 ` Noorul Islam
2010-10-27 14:09 ` Nick Dokos
2010-10-27 14:30   ` Nick Dokos
2010-10-27 15:07     ` Uwe Brauer
2010-10-27 16:38       ` Carsten Dominik
2010-10-27 17:09         ` Uwe Brauer
2010-10-27 15:24     ` Uwe Brauer [this message]
2010-10-27 15:04   ` Uwe Brauer

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

  List information: https://www.orgmode.org/

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

  git send-email \
    --in-reply-to=878w1jzmjb.fsf_-_@gilgamesch.quim.ucm.es \
    --to=oub@mat.ucm.es \
    --cc=emacs-orgmode@gnu.org \
    --cc=nicholas.dokos@hp.com \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.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).