comparison lisp/subr.el @ 11101:67231dca5f32

Change to macro, and return nil if there was no match at the specified depth.
author Simon Marshall <simon@gnu.org>
date Thu, 23 Mar 1995 08:43:08 +0000
parents e3c06f791fd8
children 9414f249cd8b
comparison
equal deleted inserted replaced
11100:2ad1ba0ac825 11101:67231dca5f32
824 (mapconcat 'identity args " "))))) 824 (mapconcat 'identity args " ")))))
825 825
826 (defmacro save-match-data (&rest body) 826 (defmacro save-match-data (&rest body)
827 "Execute the BODY forms, restoring the global value of the match data." 827 "Execute the BODY forms, restoring the global value of the match data."
828 (let ((original (make-symbol "match-data"))) 828 (let ((original (make-symbol "match-data")))
829 (list 829 (list 'let (list (list original '(match-data)))
830 'let (list (list original '(match-data))) 830 (list 'unwind-protect
831 (list 'unwind-protect 831 (cons 'progn body)
832 (cons 'progn body) 832 (list 'store-match-data original)))))
833 (list 'store-match-data original))))) 833
834 834 (defmacro match-string (num &optional string)
835 (defun match-string (n &optional string) 835 "Return string of text matched by last search.
836 "Return the Nth subexpression matched by the last regexp search or match. 836 NUM specifies which parenthesized expression in the last regexp.
837 If the last search or match was done against a string, 837 Value is nil if NUMth pair didn't match, or there were less than NUM pairs.
838 specify that string as the second argument STRING." 838 Zero means the entire text matched by the whole regexp or whole string.
839 (if string 839 STRING should be given if the last search was by `string-match' on STRING."
840 (substring string (match-beginning n) (match-end n)) 840 (list 'and (list 'match-beginning num)
841 (buffer-substring (match-beginning n) (match-end n)))) 841 (append (if string (list 'substring string) '(buffer-substring))
842 (list (list 'match-beginning num) (list 'match-end num)))))
842 843
843 (defun shell-quote-argument (argument) 844 (defun shell-quote-argument (argument)
844 "Quote an argument for passing as argument to an inferior shell." 845 "Quote an argument for passing as argument to an inferior shell."
845 ;; Quote everything except POSIX filename characters. 846 ;; Quote everything except POSIX filename characters.
846 ;; This should be safe enough even for really weird shells. 847 ;; This should be safe enough even for really weird shells.