diff --git a/helm-font.el b/helm-font.el index e4b86efc2..260bda191 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 "") 'helm-ucs-persistent-delete) (define-key map (kbd "") 'helm-ucs-persistent-backward) (define-key map (kbd "") 'helm-ucs-persistent-forward) - (define-key map (kbd "") '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."