summaryrefslogtreecommitdiff
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
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.
-rw-r--r--basic.el52
-rw-r--r--common.el15
-rw-r--r--init.el16
-rw-r--r--view-conf.el87
4 files changed, 146 insertions, 24 deletions
diff --git a/basic.el b/basic.el
index b6fd4bf..fc1740e 100644
--- a/basic.el
+++ b/basic.el
@@ -1,5 +1,11 @@
;;; -*- lexical-binding: t; -*-
+;;; No limit in printing, since I oft want to print the results of
+;;; evaluating expressions.
+
+(set 'eval-expression-print-length nil) ;; A value of nil means no limit.
+(set 'eval-expression-print-level nil) ;; A value of nil means no limit.
+
;;; Important in order to read passwords
(setq epg-pinentry-mode 'loopback)
@@ -337,6 +343,52 @@ window horizontally."
(define-key global-map (vector ?\s-D) #'dired-other-window)
(define-key global-map (vector ?\s-v) #'durand-focus-completion-or-minibuffer)
+;; I like to use winner mode now
+
+(require 'winner)
+
+(winner-mode 1)
+
+;;; Escape triggers super
+
+(define-key input-decode-map (vector 27) nil)
+(define-key input-decode-map (vector 27) #'event-apply-control-modifier)
+(define-key key-translation-map (vector 27) #'event-apply-control-modifier)
+
+;;; Don't ask me to confirm!
+
+;;;###autoload
+(defun durand-bookmark-completing-read (prompt &optional default)
+ "Prompting with PROMPT, read a bookmark name in completion.
+PROMPT will get a \": \" stuck on the end no matter what, so you
+probably don't want to include one yourself.
+Optional arg DEFAULT is a string to return if the user input is empty.
+If DEFAULT is nil then return empty string for empty input.
+
+Don't ask me to confirm my choice. --- Durand"
+ (bookmark-maybe-load-default-file) ; paranoia
+ (if (listp last-nonmenu-event)
+ (bookmark-menu-popup-paned-menu t prompt
+ (if bookmark-sort-flag
+ (sort (bookmark-all-names)
+ 'string-lessp)
+ (bookmark-all-names)))
+ (let* ((completion-ignore-case bookmark-completion-ignore-case)
+ (default (unless (equal "" default) default))
+ (prompt (concat prompt (if default
+ (format " (%s): " default)
+ ": "))))
+ (completing-read prompt
+ (lambda (string pred action)
+ (if (eq action 'metadata)
+ '(metadata (category . bookmark))
+ (complete-with-action
+ action bookmark-alist string pred)))
+ nil t nil 'bookmark-history default))))
+
+(advice-add 'bookmark-completing-read :override #'durand-bookmark-completing-read)
+
+
;;; Package management
;;;###autoload
diff --git a/common.el b/common.el
index fa6f3fe..3b75063 100644
--- a/common.el
+++ b/common.el
@@ -132,6 +132,21 @@ ARG means do this command ARG times."
(goto-char (point-max))))))))
;;;###autoload
+(defun durand-display-in-one-window (buffer _alist)
+ "Display BUFFER in one window.
+ALIST is an association list of action symbols and values. See
+Info node `(elisp) Buffer Display Action Alists' for details of
+such alists.
+
+This function pops up a new window and then deletes all other
+windows. And ALIST is completely ignored."
+ (let ((window (split-window (frame-root-window (selected-frame)))))
+ (set-window-buffer window buffer)
+ (select-window window)
+ (delete-other-windows)
+ window))
+
+;;;###autoload
(defun durand-completion-scroll-up-or-go-to-minibuffer (&optional arg)
"Scroll up; if this is not feasible, go to the mini-buffer.
ARG means do this command ARG times."
diff --git a/init.el b/init.el
index 1d238d2..2cd1ac7 100644
--- a/init.el
+++ b/init.el
@@ -110,6 +110,7 @@ If FUNCTION-NAME is already a valid function, this won't do anything."
(use-package "durand-chercher-pdf" 'durand-chercher-pdf
(define-key durand-pdf-mode-map (vector ?q) 'quit-window)
+ (define-key durand-pdf-mode-map (vector ?x) #'durand-chercher-pdf-exit)
(define-key durand-pdf-mode-map (vector ?N) 'forward-line)
(define-key durand-pdf-mode-map (vector ?n) 'durand-pdf-next-pdf-line)
(define-key durand-pdf-mode-map (vector ?P) (lambda () (interactive) (forward-line -1)))
@@ -118,7 +119,18 @@ If FUNCTION-NAME is already a valid function, this won't do anything."
(define-key durand-pdf-mode-map (vector 32) 'durand-pdf-open-or-scroll-up)
(define-key durand-pdf-mode-map (vector 'backspace) 'durand-pdf-open-or-scroll-down)
(define-key durand-pdf-mode-map (vector ?o) 'kill-other-buffer-window)
- (define-key durand-pdf-mode-map (vector ?k) 'kill-current-buffer))
+ (define-key durand-pdf-mode-map (vector ?k) 'kill-current-buffer)
+ (cond
+ ((assoc durand-chercher-pdf-buffer-name display-buffer-alist #'string-match)
+ (setcdr (assoc durand-chercher-pdf-buffer-name
+ display-buffer-alist #'string-match)
+ '((display-buffer-in-tab durand-display-in-one-window)
+ (tab-name . "chercher pdf"))))
+ (t
+ (add-to-list 'display-buffer-alist
+ `(,(rx-to-string `(seq bos ,durand-chercher-pdf-buffer-name eos))
+ (display-buffer-in-tab durand-display-in-one-window)
+ (tab-name . "chercher pdf"))))))
;;; gnus
@@ -162,7 +174,7 @@ If FUNCTION-NAME is already a valid function, this won't do anything."
;;; embark
-(load-config "embark-conf.el")
+;; (load-config "embark-conf.el")
;;; magit
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)))