From b334dac3383569265023b0fd2238564f7e5888ef Mon Sep 17 00:00:00 2001 From: jao Date: Wed, 17 Mar 2021 23:18:20 +0000 Subject: completion: dap -> cmap --- consult.org | 10 ++--- counsel.org | 124 +++++++++++++++++++++++++++++++----------------------------- 2 files changed, 68 insertions(+), 66 deletions(-) diff --git a/consult.org b/consult.org index 21e111c..6c99e77 100644 --- a/consult.org +++ b/consult.org @@ -16,7 +16,7 @@ :ensure t :custom ((selectrum-complete-in-buffer nil) (selectrum-extend-current-candidate-highlight t) - (selectrum-fix-vertical-window-height t) + (selectrum-fix-vertical-window-height nil) (selectrum-max-window-height 20) (selectrum-show-indices nil) (selectrum-count-style 'current/matches)) ;; 'matches @@ -43,8 +43,8 @@ :ensure t :bind (("C-x M-:" . consult-complex-command) ("C-x b" . consult-buffer) - ("C-x 4 b" . consult-buffer-other-window) - ("C-x 5 b" . consult-buffer-other-frame) + ;; ("C-x 4 b" . consult-buffer-other-window) + ;; ("C-x 5 b" . consult-buffer-other-frame) ("C-c b" . project-find-file) ("C-c B" . bookmark-set) ("C-c h" . consult-history) @@ -76,9 +76,7 @@ :custom ((consult-locate-command "locate --ignore-case --regexp ARG OPTS") (consult-preview-key (kbd "`")) - (consult-config '((consult-mark :preview-key any))) - (consult-narrow-key (kbd "<")) - (consult-widen-key (kbd ">"))) + (consult-config '((consult-mark :preview-key any)))) :init (fset 'multi-occur #'consult-multi-occur) diff --git a/counsel.org b/counsel.org index 07035d6..9bf0892 100644 --- a/counsel.org +++ b/counsel.org @@ -94,20 +94,21 @@ (ivy-rich-switch-buffer-project (:width 15)) (ivy-rich-switch-buffer-major-mode (:width 15 :face jao-themes-f12))))) #+end_src -* dap +* cmap #+begin_src emacs-lisp - (jao-load-path "dap") - (use-package dap + (jao-load-path "cmap") + (use-package cmap :demand t - :bind (("C-'" . dap-dap))) + :bind (("C-;" . cmap-cmap) + ("C-'" . cmap-default))) #+end_src *** prompter #+begin_src emacs-lisp - (defun jao-dap--hide-help () + (defun jao-cmap--hide-help () (when-let ((w (get-buffer-window (help-buffer)))) (with-selected-window w (kill-buffer-and-window)))) - (defun jao-dap--prompter (keymap) + (defun jao-cmap--prompter (keymap) (let ((display-buffer-alist '(("*Help*" (display-buffer-at-bottom) (window-parameters (mode-line-format . none)) @@ -115,58 +116,61 @@ (let ((inhibit-message t)) (describe-keymap keymap)))) - (defun jao-dap--prompter-done () - (save-current-buffer (jao-dap--hide-help))) + (defun jao-cmap--prompter-done () + (save-current-buffer (jao-cmap--hide-help))) - (setq dap-prompter #'jao-dap--prompter) - (setq dap-prompter-done #'jao-dap--prompter-done) + (setq cmap-prompter #'jao-cmap--prompter) + (setq cmap-prompter-done #'jao-cmap--prompter-done) #+end_src *** minibuffer actions #+begin_src emacs-lisp - (defun jao-dap--completion-metadata () + (defun jao-cmap--completion-metadata () (completion-metadata (buffer-substring-no-properties (field-beginning) (point)) minibuffer-completion-table minibuffer-completion-predicate)) - (defun jao-dap--completion-category () - (completion-metadata-get (jao-dap--completion-metadata) 'category)) + (defun jao-cmap--completion-category () + (completion-metadata-get (jao-cmap--completion-metadata) 'category)) - (dap-define-keymap jao-dap-buffer-map + (defmacro cmap-define-keymap (v d &rest b) + `(defvar ,v (cmap-keymap ,@b) ,d)) + + (cmap-define-keymap jao-cmap-buffer-map "Keymap for buffer actions." - ("k" kill-buffer) - ("b" switch-to-buffer) - ("o" switch-to-buffer-other-window) - ("z" bury-buffer) - ("q" kill-buffer-and-window) - ("=" ediff-buffers)) - - (dap-define-keymap espotify-item-keymap - "Actions for Spotify search results" - ("a" espotify--play-album) - ("h" espotify--show-info)) - - (defvar jao-dap--smaps - '((command . dap-command-map) - (espotify-search-item . espotify-item-keymap) - (function . dap-function-map) - (variable . dap-variable-map) - (face . dap-face-map) - (buffer . jao-dap-buffer-map) - (consult-buffer . jao-dap-buffer-map))) - - (defun jao-dap-target-minibuffer-candidate () + ("k" . kill-buffer) + ("b" . switch-to-buffer) + ("o" . switch-to-buffer-other-window) + ("z" . bury-buffer) + ("q" . kill-buffer-and-window) + ("=" . ediff-buffers)) + + ;; (cmap-define-keymap espotify-item-keymap + ;; "Actions for Spotify search results" + ;; ("a" espotify--play-album) + ;; ("h" espotify--show-info)) + + (defvar jao-cmap--smaps + '((command . cmap-command-map) + ;; (espotify-search-item . espotify-item-keymap) + (function . cmap-function-map) + (variable . cmap-variable-map) + (face . cmap-face-map) + (buffer . jao-cmap-buffer-map) + (consult-buffer . jao-cmap-buffer-map))) + + (defun jao-cmap-target-minibuffer-candidate () (when (minibuffer-window-active-p (selected-window)) (let ((cand (ivy-state-current ivy-last)) - (cat (jao-dap--completion-category))) - (when-let (m (alist-get cat jao-dap--smaps)) + (cat (jao-cmap--completion-category))) + (when-let (m (alist-get cat jao-cmap--smaps)) (cons m cand))))) - (add-to-list 'dap-targets #'jao-dap-target-minibuffer-candidate) + (add-to-list 'cmap-targets #'jao-cmap-target-minibuffer-candidate) #+end_src *** url / video actions #+begin_src emacs-lisp - (defvar jao-dap-video-url-rx + (defvar jao-cmap-video-url-rx (format "^https?://\\(?:www\\.\\)?%s/.+" (regexp-opt '("youtu.be" "youtube.com" @@ -176,48 +180,48 @@ t)) "A regular expression matching URLs that point to video streams") - (defun jao-dap--play-video (player url) + (defun jao-cmap--play-video (player url) (interactive "sURL: ") (let ((cmd (format "%s %s" player (shell-quote-argument url)))) (start-process-shell-command player nil cmd))) - (defun jao-dap-mpv (&optional url) + (defun jao-cmap-mpv (&optional url) "Play video stream with mpv" (interactive "sURL: ") - (jao-dap--play-video "mpv" url)) + (jao-cmap--play-video "mpv" url)) - (defun jao-dap-vlc (&optional url) + (defun jao-cmap-vlc (&optional url) "Play video stream with vlc" (interactive "sURL: ") - (jao-dap--play-video "vlc" url)) + (jao-cmap--play-video "vlc" url)) - (defun jao-dap-target-w3m-url () + (defun jao-cmap-target-w3m-url () (when-let (url (or (thing-at-point-url-at-point) (w3m-anchor) w3m-current-url)) - (cons 'dap-url-map url))) + (cons 'cmap-url-map url))) - (defun jao-dap-kill (&optional x) + (defun jao-cmap-kill (&optional x) "Save to kill ring" (interactive "s") (kill-new x)) - (define-key dap-url-map "f" #'browse-url-firefox) - (define-key dap-url-map "w" #'jao-dap-kill) - (define-key dap-url-map [return] #'browse-url) + (define-key cmap-url-map "f" #'browse-url-firefox) + (define-key cmap-url-map "w" #'jao-cmap-kill) + (define-key cmap-url-map [return] #'browse-url) - (defun jao-dap-target-video-url () - (when-let (url (jao-dap-target-w3m-url)) - (when (string-match-p jao-dap-video-url-rx (cdr url)) - (cons 'jao-dap-video-url-map (cdr url))))) + (defun jao-cmap-target-video-url () + (when-let (url (jao-cmap-target-w3m-url)) + (when (string-match-p jao-cmap-video-url-rx (cdr url)) + (cons 'jao-cmap-video-url-map (cdr url))))) - (dap-define-keymap jao-dap-video-url-map + (cmap-define-keymap jao-cmap-video-url-map "Actions on URLs pointing to remote video streams." - ("v" jao-dap-vlc) - ("m" jao-dap-mpv)) + ("v" . jao-cmap-vlc) + ("m" . jao-cmap-mpv)) - (add-to-list 'dap-targets #'jao-dap-target-w3m-url) - (add-to-list 'dap-targets #'jao-dap-target-video-url) + (add-to-list 'cmap-targets #'jao-cmap-target-w3m-url) + (add-to-list 'cmap-targets #'jao-cmap-target-video-url) #+end_src * startup #+begin_src emacs-lisp -- cgit v1.2.3