Function: cperl-make-regexp-x
cperl-make-regexp-x is a byte-compiled function defined in
cperl-mode.el.gz.
Signature
(cperl-make-regexp-x)
Documentation
Ensure that a regular expression has a "/x" modifier.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/cperl-mode.el.gz
(defun cperl-make-regexp-x ()
"Ensure that a regular expression has a \"/x\" modifier."
;; Returns position of the start
;; XXX this is called too often! Need to cache the result!
(save-excursion
(or cperl-use-syntax-table-text-property
(error "I need to have a regexp marked!"))
;; Find the start
(if (looking-at "\\s|")
nil ; good already
(if (or (looking-at "\\([smy]\\|qr\\)\\s|")
(and (eq (preceding-char) ?q)
(looking-at "\\(r\\)\\s|")))
(goto-char (match-end 1))
(re-search-backward "\\s|"))) ; Assume it is scanned already.
;;(forward-char 1)
(let ((b (point)) (e (make-marker)) have-x delim
(sub-p (eq (preceding-char) ?s)))
(forward-sexp 1)
(set-marker e (1- (point)))
(setq delim (preceding-char))
(if (and sub-p (eq delim (char-after (- (point) 2))))
(error "Possible s/blah// - do not know how to deal with"))
(if sub-p (forward-sexp 1))
(if (looking-at "\\sw*x")
(setq have-x t)
(insert "x"))
;; Protect fragile " ", "#"
(if have-x nil
(goto-char (1+ b))
(while (re-search-forward "\\(\\=\\|[^\\]\\)\\(\\\\\\\\\\)*[ \t\n#]" e t) ; Need to include (?#) too?
(forward-char -1)
(insert "\\")
(forward-char 1)))
b)))