;; Copyright (C) 2000 by Michael Abraham Shulman
-;; Author: Michael Abraham Shulman <
+;; Author: Michael Abraham Shulman <.net>
(setq string (replace-match (cdr pair) t t string))))))
-(defun mmm-format-matches (string)
+(defun mmm-format-matches (string)
"Format STRING by matches from the current match data.
Strings like ~N are replaced by the Nth subexpression from the last
-global match. Does nothing if STRING is not a string."
+global match. Does nothing if STRING is not a string.
+ON-STRING, if supplied, means to use the match data from a
+`string-match' on that string, rather than the global match data."
(let ((old-data (match-data))
(while (string-match "~\\([0-9]\\)" string)
- (setq subexp (string-to-int (match-string 1 string))
- (set-match-data old-data)
+ (setq subexp (string-to-int (match-string-no-properties 1 string))
+ (set-match-data old-data)
+ (match-string-no-properties subexp on-string))
(defmacro mmm-save-keyword (param)
"If the value of PARAM as a variable is non-nil, return the list
\(:PARAM (symbol-value PARAM)), otherwise NIL. Best used only when it
-is important that nil values
+is important that nil values disappear."
`(if (and (boundp ',param) ,param)
(list (intern (concat ":" (symbol-name ',param))) ,param)
\(let \(\(a 1) \(c 2)) \(mmm-save-keywords a b c)) ==> \(:a 1 :c 2)
Use of this macro can make code more readable when there are a lot of
PARAMS, but less readable when there are only a few. Also best used
-only when it is important that nil values
+only when it is important that nil values disappear."
`(append ,@(mapcar #'(lambda (param)
(macroexpand `(mmm-save-keyword ,param)))
+;; Mostly for remembering interactively made regions
+(defun mmm-make-marker (pos beg-p sticky-p)
+ "Make, and return, a marker at POS that is or isn't sticky.
+BEG-P represents whether the marker delimits the beginning of a
+region \(or the end of it). STICKY-P is whether it should be sticky,
+i.e. whether text inserted at the marker should be inside the region."
+ (let ((mkr (set-marker (make-marker) pos)))
+ (set-marker-insertion-type mkr (if beg-p (not sticky-p) sticky-p))