Skip to content

haji-ali/transient-extras

Repository files navigation

transient-extras - Extensions and application menus based on transient

Introduction

This package provides a set of extensions to transient and interactive menus to common UNIX tools and applications.

transient-extras

transient-extras provides a set of extensions to transient to make writing the provided menus easier. It includes the following extensions

transient-extras-file-list-or-buffer

This provides a pre-defined argument usable in a transient. It contains either the current buffer, the filename for the current buffer, or the names of the files currently marked in dired.

transient-extras-exclusive-switch

This class allows the definition of command line switches with options to be quickly cycled through. This is similar to the default transient-switches, but allows value/label pairs to be used instead, for example:

(transient-define-argument transient-extras-lp--orientation ()
  :description "Print Orientation"
  :class 'transient-extras-exclusive-switch
  :key "o"
  :argument-format "-oorientation-requested=%s"
  :argument-regexp "\\(-oorientation-requested=\\(4\\|5\\|6\\)\\)"
  :choices '(("4" . "90°(landscape)")
             ("5" . "-90°")
             ("6" . "180°")))

transient-extras-option-dynamic-choices

This class allows the values of an option to be determined dynamically through the use of a choices-function. This is useful for programs for which option arguments are configurable externally to Emacs. For example:

(transient-define-argument transient-extras-a2ps-printer ()
  :class 'transient-extras-option-dynamic-choices
  :description "Printer"
  :key "P"
  :argument "-P"
  :choices-function (transient-extras-make-command-filter-function
                     "a2ps" '("--list=printers")
                     (lambda (line)
                       (when (and (string-match-p "^-" line)
                                  (not (string-match-p "Default" line))
                                  (not (string-match-p "Unknown" line)))
                         (substring line 2))))
  :prompt "Printer? ")

Additional Functions

transient-extras-make-command-filter-function

This function is used to make a function which filters the output of a command. It takes three arguments: the program name, the arguments to the command, and a function to filter each line of output. An example of use is shown above.

transient-extras-lp

screenshots/transient-extras-lp.png

transient-extras-lp provides a menu based on transient to call the CUPS printing program lp on the current buffer or a selected file.

transient-extras-lp can be enabled for dired and pdf-tools buffers as follows (make sure that transient-extras.el is in load-path)

(require 'transient-extras-lp)

(with-eval-after-load 'dired
  (define-key
    dired-mode-map
    (kbd "C-c C-p") #'transient-extras-lp-menu))

(with-eval-after-load 'pdf-tools
  (define-key
    pdf-misc-minor-mode-map
    (kbd "C-c C-p") #'transient-extras-lp-menu))

Or simply call transient-extras-lp-menu to print the current buffer or the selected files in dired. If a buffer has an associated file, the file is printed, otherwise the buffer content is sent to lp.

Additional Configuration

By pressing d, you can input the name of the printer. The command lpstat -a is used to get a list of installed and network printers. If you have async-completing-read, you may want to define the following advice to run the command asynchronously.

(define-advice transient-extras-lp--read-printer
    (:override (prompt initial-input history)
               my/transient-extras-lp--read-printer)
  (let ((preprocess-lines-fun
         (lambda (x)
           (mapcar
            (lambda (y)
              (let ((ind (string-match "[[:space:]]" y)))
                (if ind
                    (substring y nil ind)
                  y)))
            x))))
    (async-completing-read
     prompt
     (apply #'acr-preprocess-lines-from-process
            'lines-from-process  ;; cateogry
            preprocess-lines-fun
            transient-extras-lp-get-printers-cmd)
     nil nil initial-input history)))

transient-extras-a2ps

screenshots/transient-extras-a2ps.png

transient-extras-a2ps provides a menu to call the a2ps printing program on the current buffer or selected file.

transient-extras-a2ps may be enabled for dired or other buffers using the following code (assuming transient-extras.el is in the load-path):

(require 'transient-extras-a2ps)

(global-set-key (kbd "C-c C-p") #'transient-extras-a2ps)

Note that this binding will be shadowed in places where it is specifically bound in a local map.

Additional Configuration

All additional configuration and description of options may be found in the a2ps info manual.

About

A transient menu for lp

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published