Function: projectile--define-display-variants

projectile--define-display-variants is a macro defined in projectile.el.

Signature

(projectile--define-display-variants BASE ARGLIST DOCSTRING &rest BODY)

Documentation

Define other-window/other-frame variants of the Projectile command BASE.

Defines the commands BASE-other-window and BASE-other-frame. Each takes ARGLIST as its argument list; when ARGLIST is non-empty the commands read the raw prefix argument (all such variants mirror a base command with an (interactive "P") spec). DOCSTRING is a format string; every %s in it is filled in with "window" or "frame".

BODY is the body of the other-window variant. The other-frame variant is derived from it by replacing "other-window" with "other-frame" inside every symbol, so bodies reference display functions like find-file-other-window and get the frame flavor for free.

If BODY starts with the keyword :places followed by a list, only the variants for the listed places are defined, e.g. (window) for commands that have no other-frame counterpart.

Source Code

;; Defined in ~/.emacs.d/elpa/projectile-20260820.1509/projectile.el
(defmacro projectile--define-display-variants (base arglist docstring &rest body)
  "Define other-window/other-frame variants of the Projectile command BASE.

Defines the commands `BASE-other-window' and `BASE-other-frame'.  Each
takes ARGLIST as its argument list; when ARGLIST is non-empty the
commands read the raw prefix argument (all such variants mirror a base
command with an (interactive \"P\") spec).  DOCSTRING is a format
string; every `%s' in it is filled in with \"window\" or \"frame\".

BODY is the body of the other-window variant.  The other-frame variant
is derived from it by replacing \"other-window\" with \"other-frame\"
inside every symbol, so bodies reference display functions like
`find-file-other-window' and get the frame flavor for free.

If BODY starts with the keyword :places followed by a list, only the
variants for the listed places are defined, e.g. (window) for commands
that have no other-frame counterpart."
  (declare (indent 2) (doc-string 3))
  (let ((places '(window frame)))
    (when (eq (car body) :places)
      (setq places (cadr body)
            body (cddr body)))
    `(progn
       ,@(mapcar
          (lambda (place)
            (let ((name (intern (format "%s-other-%s" base place)))
                  (body (if (eq place 'window)
                            body
                          (projectile--substitute-in-symbols
                           body "other-window" "other-frame")))
                  (%-count (1- (length (split-string docstring "%s")))))
              `(defun ,name ,arglist
                 ,(apply #'format docstring (make-list %-count place))
                 (interactive ,@(when arglist '("P")))
                 ,@body)))
          places))))