summaryrefslogtreecommitdiff
path: root/view-conf.el
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2021-01-27 18:34:52 +0800
committerJSDurand <mmemmew@gmail.com>2021-01-27 18:39:30 +0800
commit43afe6c5db55704f787aaee4cedd7f4c69206b8b (patch)
treebbaa1c90455801023c9f99ccfa175b1c5c121e9c /view-conf.el
parent4108bfb79643248821fb1d62cae9a4ac7146f1bc (diff)
Further configurations
* basic.el (eval-expression-print-length): (eval-expression-print-level): Now echo are will print without limits. (winner): Enable winner-mode at start up. (input-decode-map): (key-translation-map): Translate ESC to make the following key modified by control. (bookmark-completing-read): (durand-bookmark-completing-read): Now it won't ask me for confirmation about my choices. * init.el ("durand-chercher-pdf"): Further enhance the convenience of viewing PDFs. ("embark-conf.el"): Now I don't use embark anymore. * view-conf.el (durand-view-map): Add my own way of viewing things. (durand-open-targets): These are the things I can open. (durand-open-object): Open things quickly.
Diffstat (limited to 'view-conf.el')
-rw-r--r--view-conf.el87
1 files changed, 65 insertions, 22 deletions
diff --git a/view-conf.el b/view-conf.el
index ca08409..5465b89 100644
--- a/view-conf.el
+++ b/view-conf.el
@@ -93,10 +93,11 @@ If ARG is '(16), view the battery information."
(defvar durand-view-map
;; Against every good principle I guess...
(let ((map (list 'keymap "View")))
- (define-key map (vector ?v) 'view-mode)
- (define-key map (vector ?p) #'durand-view-process)
+ (define-key map (vector ?v) #'view-mode)
+ (define-key map (vector ?P) #'durand-view-process)
(define-key map (vector ?t) #'durand-view-timers-or-temps)
(define-key map (vector ?e) #'eshell)
+ (define-key map (vector ?p) #'durand-chercher-pdf)
map)
"The keymap that is related to my custom functions about viewing.")
@@ -114,13 +115,57 @@ If ARG is '(16), view the battery information."
;;;###autoload
(defvar durand-open-targets
- (list (list "safari" "open" "-a" "Safari" -1)
- (list "terminal" "open" "-a" "Terminal" -1))
+ (list (list "Safari" "open" "-a" "Safari" (list "https://www.youtube.com"
+ "https://www.gmail.com"
+ "https://www.facebook.com"
+ "https://protesilaos.com"))
+ (list "Terminal" "open" "-a" "Terminal" -1))
"Targets to open by `durand-open-object'.
This is an association list whose elements have `car' equal to
the choice presented to the user, and have `cdr' a list that will
-be passed to `make-process'.")
+be passed to `make-process'.
+
+See the documentation for `durand-open-object' for the formats of
+targets.")
+
+;;;###autoload
+(defun durand-target-extra-arg (target)
+ "Determine if TARGET has room for extra arguments.
+
+This returns the list of extra argument slots, or nil if there is
+none."
+ (let (temp result)
+ (while (consp target)
+ (setq temp (car target))
+ (setq target (cdr target))
+ (cond
+ ((eq temp -1)
+ (setq result (cons -1 result)))
+ ((consp temp)
+ (setq result (cons temp result)))))
+ (nreverse result)))
+
+;;;###autoload
+(defun durand-replace-extra-args (target extra-args)
+ "Replace slots for extra-args in TARGET by EXTRA-ARGS.
+
+This does not check if the lengths match, though in theory they
+should.
+
+And this will delete any `nil' values from the result."
+ (let (temp result)
+ (while (consp target)
+ (setq temp (car target))
+ (setq target (cdr target))
+ (cond
+ ((or (eq temp -1)
+ (consp temp))
+ (setq result (cons (car extra-args)
+ result))
+ (setq extra-args (cdr extra-args)))
+ ((setq result (cons temp result)))))
+ (delq nil (nreverse result))))
;;;###autoload
(defun durand-open-object (&optional arg)
@@ -130,27 +175,25 @@ What can be opened is controlled by the variable
`durand-open-targets'.
If ARG is non-nil, and if the chosen target contains `-1' in the
-command line options, then read a string to replace that -1."
+command line options, then read a string to replace that -1. If
+the chosen target has a sub-list, then use that sub-list as
+options to choose from."
(interactive "P")
(let* ((targets durand-open-targets)
(choice (completing-read "Open: " targets nil t))
(commands (cdr (assoc choice targets #'string=)))
- (contain-minus-one-p (memq -1 commands))
- (extra (cond
- ((and arg contain-minus-one-p)
- (read-string "Extra argument: "))))
- temp)
- (cond
- (contain-minus-one-p
- (setq commands (progn
- (while (consp commands)
- (cond
- ((eq (car commands) -1)
- (setq temp (cons extra temp)))
- ((setq temp (cons (car commands) temp))))
- (setq commands (cdr commands)))
- (reverse temp)))))
- (setq conmmands (delq nil commands))
+ (extra-arg-slots (durand-target-extra-arg commands))
+ (extra-arg (cond
+ (arg
+ (mapcar (lambda (extra-arg-slot)
+ (cond
+ ((eq extra-arg-slot -1)
+ (read-string "Extra argument: "))
+ ((consp extra-arg-slot)
+ (completing-read
+ "Extra argument: " extra-arg-slot))))
+ extra-arg-slots)))))
+ (setq commands (durand-replace-extra-args commands extra-arg))
(make-process :name "durand-open"
:buffer nil
:command commands)))