summaryrefslogtreecommitdiff
path: root/helm-font.el
diff options
context:
space:
mode:
authorThierry Volpiatto <thierry.volpiatto@gmail.com>2016-02-07 10:11:03 +0100
committerThierry Volpiatto <thierry.volpiatto@gmail.com>2016-02-07 10:11:03 +0100
commit9f4cb3ec479f7368a899f6ede71d50e7a9aaeff8 (patch)
treefbca172743dd1f6cc7026ff6cee7d9824a2f595b /helm-font.el
parenta1cebfa2f68c9f8240acca7b7cac671bb17c5a04 (diff)
Allow matching char at point change alignment (#1365).
Alignment still not fully fixed. * helm-font.el (helm-calculate-ucs-max-len): Return again a cons. (helm-ucs-init): Change again alignment. (helm-ucs-insert): Fix regexp. (helm-ucs-insert-char): Use it. (helm-ucs-insert-code): Use it. (helm-ucs): Allow matching char at point.
Diffstat (limited to 'helm-font.el')
-rw-r--r--helm-font.el25
1 files changed, 15 insertions, 10 deletions
diff --git a/helm-font.el b/helm-font.el
index afc0c290..605ab6c3 100644
--- a/helm-font.el
+++ b/helm-font.el
@@ -73,8 +73,10 @@
;; (multibyte-string-p "⃩ xx123")
(defun helm-calculate-ucs-max-len ()
"Calculate the length of longest `ucs-names' candidate."
- (cl-loop for (_n . v) in (ucs-names) maximize
- (max 1 (string-width (format "%c #x%x:" v v)))))
+ (cl-loop for (_n . v) in (ucs-names)
+ maximize (length (format "#x%x:" v)) into code
+ maximize (max 1 (string-width (format "%c" v))) into char
+ finally return (cons code char)))
(defun helm-ucs-init ()
"Initialize an helm buffer with ucs symbols.
@@ -85,10 +87,11 @@ Only math* symbols are collected."
(or helm-ucs--names
(setq helm-ucs--names
(cl-loop for (n . v) in (ucs-names)
- for len = (max 1 (string-width (format "%c #x%x:" v v)))
- for diff = (+ helm-ucs--max-len (- helm-ucs--max-len len))
+ for len = (length (format "#x%x:" v))
+ for diff = (- (car helm-ucs--max-len) len)
unless (string= "" n) collect
- (format "%c #x%x:%s%s" v v (make-string diff ? ) n)))))
+ (format "#x%x:%s%c%s%s"
+ v (make-string diff ? ) v (make-string 5 ? ) n)))))
(defun helm-ucs-forward-char (_candidate)
(with-helm-current-buffer
@@ -104,16 +107,16 @@ Only math* symbols are collected."
(defun helm-ucs-insert (candidate n)
(when (string-match
- "^\\(.\\) \\(#x[a-f0-9]+\\):\\([^:]+\\)+"
+ "^\\(#x[a-f0-9]+\\): \\(.\\) +\\([^:]+\\)+"
candidate)
(with-helm-current-buffer
(insert (match-string n candidate)))))
(defun helm-ucs-insert-char (candidate)
- (helm-ucs-insert candidate 1))
+ (helm-ucs-insert candidate 2))
(defun helm-ucs-insert-code (candidate)
- (helm-ucs-insert candidate 2))
+ (helm-ucs-insert candidate 1))
(defun helm-ucs-insert-name (candidate)
(helm-ucs-insert candidate 3))
@@ -172,8 +175,10 @@ Only math* symbols are collected."
(defun helm-ucs ()
"Preconfigured helm for `ucs-names' math symbols."
(interactive)
- (helm :sources 'helm-source-ucs
- :keymap helm-ucs-map))
+ (let ((char (string (char-after))))
+ (helm :sources 'helm-source-ucs
+ :keymap helm-ucs-map
+ :input (and (multibyte-string-p char) char))))
(provide 'helm-font)