Skip to content

Commit f3f3b40

Browse files
author
Thierry Volpiatto
committed
Avoid using ring in helm-ucs
* helm-font.el (helm-ucs-recent): Initial value is now nil. (helm-ucs-save-recentest): New, replace ring-remove+insert+extend. (helm-ucs-insert): Use it. (helm-ucs-kill-char): Use it. (helm-ucs-kill-code): Use it. (helm-ucs-kill-name): Use it. (helm-source-ucs-recent): Use helm-ucs-recent value in a lambda.
1 parent 253627f commit f3f3b40

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

helm-font.el

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
(require 'cl-lib)
2121
(require 'helm)
2222
(require 'helm-help)
23-
(require 'ring)
2423

2524

2625
(defgroup helm-font nil
@@ -93,7 +92,7 @@
9392
(defvar helm-ucs--max-len nil)
9493
(defvar helm-ucs--names nil)
9594
(defvar helm-ucs-history nil)
96-
(defvar helm-ucs-recent (make-ring helm-ucs-recent-size)
95+
(defvar helm-ucs-recent nil
9796
"Ring of recent `helm-ucs' selections.")
9897

9998
(defun helm-calculate-ucs-alist-max-len (names)
@@ -192,10 +191,17 @@ Where N=1 is the ucs code, N=2 the ucs char and N=3 the ucs name."
192191
candidate)
193192
(match-string n candidate)))
194193

194+
(defun helm-ucs-save-recentest (candidate)
195+
(let ((lst (cons candidate (delete candidate helm-ucs-recent))))
196+
(setq helm-ucs-recent
197+
(if (> (length lst) helm-ucs-recent-size)
198+
(nbutlast lst 1)
199+
lst))))
200+
195201
(defun helm-ucs-insert (candidate n)
196202
"Insert the N part of CANDIDATE."
197203
(with-helm-current-buffer
198-
(ring-remove+insert+extend helm-ucs-recent candidate)
204+
(helm-ucs-save-recentest candidate)
199205
(insert (helm-ucs-match candidate n))))
200206

201207
(defun helm-ucs-insert-char (candidate)
@@ -215,17 +221,17 @@ Where N=1 is the ucs code, N=2 the ucs char and N=3 the ucs name."
215221
"Action that concatenate ucs marked chars."
216222
(let ((marked (helm-marked-candidates)))
217223
(cl-loop for candidate in marked
218-
do (ring-remove+insert+extend helm-ucs-recent candidate))
224+
do (helm-ucs-save-recentest candidate))
219225
(kill-new (mapconcat (lambda (x)
220226
(helm-ucs-match x 2))
221227
marked ""))))
222228

223229
(defun helm-ucs-kill-code (candidate)
224-
(ring-remove+insert+extend helm-ucs-recent candidate)
230+
(helm-ucs-save-recentest candidate)
225231
(kill-new (helm-ucs-match candidate 1)))
226232

227233
(defun helm-ucs-kill-name (candidate)
228-
(ring-remove+insert+extend helm-ucs-recent candidate)
234+
(helm-ucs-save-recentest candidate)
229235
(kill-new (helm-ucs-match candidate 3)))
230236

231237
;; Navigation in current-buffer (persistent)
@@ -276,7 +282,7 @@ Where N=1 is the ucs code, N=2 the ucs char and N=3 the ucs name."
276282
(defvar helm-source-ucs-recent
277283
(helm-build-sync-source "Recent UCS"
278284
:action helm-ucs-actions
279-
:candidates (lambda () (ring-elements helm-ucs-recent))
285+
:candidates (lambda () helm-ucs-recent)
280286
:help-message helm-ucs-help-message
281287
:keymap helm-ucs-map
282288
:match-part (lambda (candidate) (cadr (split-string candidate ":")))

0 commit comments

Comments
 (0)