diff options
author | Thierry Volpiatto <thierry.volpiatto@gmail.com> | 2018-04-06 14:21:33 +0200 |
---|---|---|
committer | Thierry Volpiatto <thierry.volpiatto@gmail.com> | 2018-04-06 15:05:27 +0200 |
commit | 253627ff4769a2e95fe0a119ce325ed14d2d86f5 (patch) | |
tree | 3ba1e478adf308787a553a7e60471550b05fb3bd /helm-font.el | |
parent | bf58ccde0df420a314623d777b3f5e7363081223 (diff) |
Cleanup helm-font
* helm-font.el (helm-ucs-actions): Now a defcustom.
(helm-ucs-kill-code): Save to ring.
(helm-source-ucs): Add PA.
(helm-ucs-map): Remove old binding.
(helm-ucs-insert): Save to ring.
(helm-ucs-kill-char): Save to ring.
(helm-ucs-kill-name): Save to ring.
Diffstat (limited to 'helm-font.el')
-rw-r--r-- | helm-font.el | 60 |
1 files changed, 29 insertions, 31 deletions
diff --git a/helm-font.el b/helm-font.el index e4b86efc..260bda19 100644 --- a/helm-font.el +++ b/helm-font.el @@ -22,6 +22,7 @@ (require 'helm-help) (require 'ring) + (defgroup helm-font nil "Related applications to display fonts in helm." :group 'helm) @@ -31,13 +32,23 @@ :type 'integer :group 'helm-font) +(defcustom helm-ucs-actions + '(("Insert character" . helm-ucs-insert-char) + ("Insert character name" . helm-ucs-insert-name) + ("Insert character code in hex" . helm-ucs-insert-code) + ("Kill marked characters" . helm-ucs-kill-char) + ("Kill name" . helm-ucs-kill-name) + ("Kill code" . helm-ucs-kill-code)) + "Actions for `helm-source-ucs'." + :group 'helm-font + :type '(alist :key-type string :value-type function)) + (defvar helm-ucs-map (let ((map (make-sparse-keymap))) (set-keymap-parent map helm-map) (define-key map (kbd "<C-backspace>") 'helm-ucs-persistent-delete) (define-key map (kbd "<C-left>") 'helm-ucs-persistent-backward) (define-key map (kbd "<C-right>") 'helm-ucs-persistent-forward) - (define-key map (kbd "<C-return>") 'helm-ucs-persistent-insert) (define-key map (kbd "C-c SPC") 'helm-ucs-persistent-insert-space) map) "Keymap for `helm-ucs'.") @@ -46,7 +57,7 @@ '((((class color) (background dark)) (:foreground "Gold"))) "Face used to display ucs characters." :group 'helm-font) - + ;;; Xfont selection ;; ;; @@ -75,12 +86,15 @@ (kill-new new-font)) :persistent-help "Preview font and copy to kill-ring")) + ;;; 𝕌𝕔𝕤 𝕊𝕪𝕞𝕓𝕠𝕝 𝕔𝕠𝕞𝕡𝕝𝕖𝕥𝕚𝕠𝕟 ;; ;; (defvar helm-ucs--max-len nil) (defvar helm-ucs--names nil) (defvar helm-ucs-history nil) +(defvar helm-ucs-recent (make-ring helm-ucs-recent-size) + "Ring of recent `helm-ucs' selections.") (defun helm-calculate-ucs-alist-max-len (names) "Calculate the length of the longest NAMES list candidate." @@ -181,6 +195,7 @@ Where N=1 is the ucs code, N=2 the ucs char and N=3 the ucs name." (defun helm-ucs-insert (candidate n) "Insert the N part of CANDIDATE." (with-helm-current-buffer + (ring-remove+insert+extend helm-ucs-recent candidate) (insert (helm-ucs-match candidate n)))) (defun helm-ucs-insert-char (candidate) @@ -195,25 +210,22 @@ Where N=1 is the ucs code, N=2 the ucs char and N=3 the ucs name." "Insert ucs name part of CANDIDATE at point." (helm-ucs-insert candidate 3)) -(defun helm-ucs-persistent-insert () - "Insert ucs char without quitting helm." - (interactive) - (with-helm-alive-p - (helm-attrset 'action-insert 'helm-ucs-insert-char) - (helm-execute-persistent-action 'action-insert))) -(put 'helm-ucs-persistent-insert 'helm-only t) - ;; Kill actions (defun helm-ucs-kill-char (_candidate) "Action that concatenate ucs marked chars." - (kill-new (mapconcat (lambda (x) - (helm-ucs-match x 2)) - (helm-marked-candidates) ""))) + (let ((marked (helm-marked-candidates))) + (cl-loop for candidate in marked + do (ring-remove+insert+extend helm-ucs-recent candidate)) + (kill-new (mapconcat (lambda (x) + (helm-ucs-match x 2)) + marked "")))) (defun helm-ucs-kill-code (candidate) + (ring-remove+insert+extend helm-ucs-recent candidate) (kill-new (helm-ucs-match candidate 1))) (defun helm-ucs-kill-name (candidate) + (ring-remove+insert+extend helm-ucs-recent candidate) (kill-new (helm-ucs-match candidate 3))) ;; Navigation in current-buffer (persistent) @@ -261,23 +273,6 @@ Where N=1 is the ucs code, N=2 the ucs char and N=3 the ucs name." (helm-attrset 'action-insert-space 'helm-ucs-insert-space) (helm-execute-persistent-action 'action-insert-space))) -(defvar helm-ucs-recent (make-ring helm-ucs-recent-size) - "Ring of recent `helm-ucs' selections.") - -(defvar helm-ucs-actions - (let ((actions '(("Insert character" . helm-ucs-insert-char) - ("Insert character name" . helm-ucs-insert-name) - ("Insert character code in hex" . helm-ucs-insert-code) - ("Kill marked characters" . helm-ucs-kill-char) - ("Kill name" . helm-ucs-kill-name) - ("Kill code" . helm-ucs-kill-code)))) - (cl-loop for (name . action) in actions - for new-action = `(lambda (candidate) - (ring-remove+insert+extend helm-ucs-recent candidate) - (funcall #',action candidate)) - collect (cons name new-action))) - "Actions for `helm-source-ucs'.") - (defvar helm-source-ucs-recent (helm-build-sync-source "Recent UCS" :action helm-ucs-actions @@ -296,9 +291,12 @@ Where N=1 is the ucs code, N=2 the ucs char and N=3 the ucs name." :filtered-candidate-transformer (lambda (candidates _source) (sort candidates #'helm-generic-sort-fn)) :action helm-ucs-actions + :persistent-action (lambda (candidate) + (helm-ucs-insert-char candidate) + (helm-force-update)) :keymap helm-ucs-map) "Source for collecting `ucs-names' math symbols.") - + ;;;###autoload (defun helm-select-xfont () "Preconfigured `helm' to select Xfont." |