From 7b4b6aab3ee6fd5940bccf4ba80d65896d69d8b4 Mon Sep 17 00:00:00 2001 From: Andreas Gerler Date: Sun, 1 Feb 2026 11:46:04 +0100 Subject: [PATCH] fix helm yasnippet selection * bba.org: newcode snippet fetched from emacswiki solved the error message while selection :res --- bba.org | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/bba.org b/bba.org index 6e210e70..f9cbd0c6 100644 --- a/bba.org +++ b/bba.org @@ -719,7 +719,7 @@ snippets for =aws cli= are awesome! (setq auto-insert-directory "~/.emacs.d/templates") (define-key global-map "\C-cy" 'yas-insert-snippet) (if (>= emacs-major-version 24) - (add-to-list 'yas-prompt-functions 'yas-shk-helm-prompt)) + (add-to-list 'yas-prompt-functions 'shk-yas/helm-prompt)) (defun ha-autoinsert-yas-expand() "Replace text in yasnippet template." (yas-expand-snippet (buffer-string) (point-min) (point-max))) @@ -734,27 +734,27 @@ snippets for =aws cli= are awesome! #+END_SRC From http://emacswiki.org/emacs/Yasnippet + #+begin_src emacs-lisp - (if (>= emacs-major-version 24) - (defun yas-shk-helm-prompt (prompt choices &optional display-fn) - "Use helm to select a snippet. Put this into `yas/prompt-functions.'" - (interactive) - (setq display-fn (or display-fn 'identity)) - (if (require 'helm-misc) - (let (tmpsource cands result rmap) - (setq cands (mapcar (lambda (x) (funcall display-fn x)) choices)) - (setq rmap (mapcar (lambda (x) (cons (funcall display-fn x) x)) choices)) - (setq tmpsource - (list - (cons 'name prompt) - (cons 'candidates cands) - '(action . (("Expand" . (lambda (selection) selection)))) - )) - (setq result (helm-other-buffer '(tmpsource) "*helm-select-yasnippet")) - (if (null result) - (signal 'quit "user quit!") - (cdr (assoc result rmap)))) - nil))) + (defun shk-yas/helm-prompt (prompt choices &optional display-fn) + "Use helm to select a snippet. Put this into `yas-prompt-functions.'" + (interactive) + (if (require 'helm-config nil t) + (let ((result (helm-other-buffer + (list `((name . ,prompt) + (candidates . ,(if display-fn (mapcar display-fn choices) + choices)) + (action . (("Expand" . identity))))) + "*helm-select-yasnippet"))) + (cond ((null result) + (signal 'quit "user quit!")) + (display-fn + (catch 'result + (dolist (choice choices) + (when (equal (funcall display-fn choice) result) + (throw 'result choice))))) + (t result))) + nil)) #+end_src Default to snippet-mode if we are in a sub directory of snippets: -- 2.47.3