/[emacs]/emacs/lisp/subr.el
ViewVC logotype

Diff of /emacs/lisp/subr.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.428 by kfstorm, Tue Nov 23 15:23:57 2004 UTC revision 1.429 by monnier, Mon Dec 6 15:11:51 2004 UTC
# Line 2188  and replace a sub-expression, e.g. Line 2188  and replace a sub-expression, e.g.
2188        ;; Reconstruct a string from the pieces.        ;; Reconstruct a string from the pieces.
2189        (setq matches (cons (substring string start l) matches)) ; leftover        (setq matches (cons (substring string start l) matches)) ; leftover
2190        (apply #'concat (nreverse matches)))))        (apply #'concat (nreverse matches)))))
2191    
2192    (defun subregexp-context-p (regexp pos &optional start)
2193      "Return non-nil if POS is in a normal subregexp context in REGEXP.
2194    A subregexp context is one where a sub-regexp can appear.
2195    A non-subregexp context is for example within brackets, or within a repetition
2196    bounds operator \\{..\\}, or right after a \\.
2197    If START is non-nil, it should be a position in REGEXP, smaller than POS,
2198    and known to be in a subregexp context."
2199      ;; Here's one possible implementation, with the great benefit that it
2200      ;; reuses the regexp-matcher's own parser, so it understands all the
2201      ;; details of the syntax.  A disadvantage is that it needs to match the
2202      ;; error string.
2203      (condition-case err
2204          (progn
2205            (string-match (substring regexp (or start 0) pos) "")
2206            t)
2207        (invalid-regexp
2208         (not (member (cadr err) '("Unmatched [ or [^"
2209                                   "Unmatched \\{"
2210                                   "Trailing backslash")))))
2211      ;; An alternative implementation:
2212      ;; (defconst re-context-re
2213      ;;   (let* ((harmless-ch "[^\\[]")
2214      ;;          (harmless-esc "\\\\[^{]")
2215      ;;          (class-harmless-ch "[^][]")
2216      ;;          (class-lb-harmless "[^]:]")
2217      ;;          (class-lb-colon-maybe-charclass ":\\([a-z]+:]\\)?")
2218      ;;          (class-lb (concat "\\[\\(" class-lb-harmless
2219      ;;                            "\\|" class-lb-colon-maybe-charclass "\\)"))
2220      ;;          (class
2221      ;;           (concat "\\[^?]?"
2222      ;;                   "\\(" class-harmless-ch
2223      ;;                   "\\|" class-lb "\\)*"
2224      ;;                   "\\[?]"))     ; special handling for bare [ at end of re
2225      ;;          (braces "\\\\{[0-9,]+\\\\}"))
2226      ;;     (concat "\\`\\(" harmless-ch "\\|" harmless-esc
2227      ;;             "\\|" class "\\|" braces "\\)*\\'"))
2228      ;;   "Matches any prefix that corresponds to a normal subregexp context.")
2229      ;; (string-match re-context-re (substring regexp (or start 0) pos))
2230      )
2231    
2232  (defun shell-quote-argument (argument)  (defun shell-quote-argument (argument)
2233    "Quote an argument for passing as argument to an inferior shell."    "Quote an argument for passing as argument to an inferior shell."

Legend:
Removed from v.1.428  
changed lines
  Added in v.1.429

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26