emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ELPA] New package: xr


From: Mattias Engdegård
Subject: Re: [ELPA] New package: xr
Date: Wed, 27 Feb 2019 17:22:16 +0100

27 feb. 2019 kl. 16.06 skrev Michael Heerdegen <address@hidden>:
> 
> Would it be possible to define a variable to control what kind of
> operators `xr--postfix' chooses?  Currently the verbose names are
> hardcoded, and even if there is no perfectly nice solution, it would be
> good if there was some way to control this.  I'm not sure if there are
> other places besides `xr--postfix' where such a variable would be to
> consulted.

The identifiers chosen by xr will never suit the taste of everyone, but I 
couldn't make up my mind about what to do about it. I'd be interested in 
hearing what other people think.
One way would be to add an optional translation alist to xr:

(xr "a*.?"
    '((zero-or-more . 0+) (nonl . not-newline)))
=> (seq (0+ "a") (opt not-newline))

but this could be done almost as easily by post-processing the resulting list 
tree, maybe like this:

(defun rename-rx (substitution-alist rx)
  "Rename all identifiers in RX according to SUBSTITUTION-ALIST."
  (cond
   ((symbolp rx) (alist-get rx substitution-alist rx))
   ((consp rx)
    ;; Translate the first element of each list even if not a symbol,
    ;; to allow translation of ? and ?? (space and ?).
    (cons (alist-get (car rx) substitution-alist (car rx))
          (mapcar (lambda (elem) (rename-rx substitution-alist elem))
                  (cdr rx))))
   (t rx)))

Post-processing is more generally powerful since it can do structural 
replacement and not mere symbol replacement.

A customisable setting would also work, but I prefer keeping xr purely 
functional.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]