0

BRIEF: looking for an elisp package to make it easier and more to wrapperize calling interactive commands, temporarily overriding global variables as if by let.

---+ DETAIL:

ISO = In Search Of. I know how to write this - I have written many specific versions of this sort of thing - but I wonder if anyone has written a generic version (before I start writing one myself).

EMACS uses many global variables to control the behavior of interactive commands (and much else).

E.g. the global variable diff-switches is used to control the flavor of diff used by diff.el diff files, diff-buffers, and diff-buffer-with-file, while vc.el uses a more complicated path that ultimately uses diff-switches.

Some commands have more complicated sets of global variables: e.g. shell-mode: default-directory, shell-file-name, explicit-csh-args, bash args, etc...

I often find myself temporarily overriding such globals, sometimes for particular commands, and sometimes prompting, e.g.

(defun vc-diff-with-switches (switches)
  (interactive "sdiff-switches: ")
  (let
    ( ; override all switches on "path"
      (vc-git-diff-switches switches)
      (vcdiff-switches switches)
      (diff-switches switches) )
    (vc-diff)  ;; implicitly uses global diff-switches
    )
  )

Raising minor design issues for such wrapper functions that override global variables and then call a wrappee function: (a) should they use default values if no prefix argument, and override only if a prefix; (b) should they call-interactively the wrappee, so that's its original prefix functionality can be maintained (e.g. for vc-diff, prompting for revisions); (c) if multiple such arguments, should we loop in a fixed order, or should we use completion to allow the user to specify some but not all of the most cvommon global variables to be overridden; (d) should the values be string, numeric, or lisp expressions that might be combined with other code, etc.

E.g.

(defun call-interactively-overriding-some-globals (cmd let-list)
  "prompt to temporarily override globals in LET-LIST, then invoke CMD interactively"
  ...

Or perhaps the following example of invoking a similar but different pattern

M-x call-interactively-overriding-globals {enter}
Global to override: default-directory {enter}
Value: /tmp {enter}
Global to override: explicit-shell-file-name {enter}
Value: funky-bash {enter}
Global to override: {enter}
Command: shell {enter}

Bonus points if it can automatically create a GUI widget with fields to fill in for the various global variables to override.

Bonus points if there is some consistent way of handling prefix arguments to be passed to the wrappee, or not.

Bonus points if the boundary between global variables and command/function arguments can be smashed - making globals look like keyword arguments, etc. Perhaps by using introspection.

Background motivation: historically I might just have whipped up some ad-hoc elisp code for this as needed. However, because of computeritis I type less and use speech recognition more, so such a prompting system might be easier to control by speech than dictating elisp.

This seems like a simple thing - I would not be surprised if it has already been written.

Krazy Glew
  • 242
  • 2
  • 8
  • This isn't a question; it's an invitation to discussion. There are multiple questions, and they aren't specific. For such an open, unclear invitation to help, try a discussion site such as Reddit. – Drew Mar 07 '23 at 22:21

0 Answers0