diff options
author | Thierry Volpiatto <thierry.volpiatto@gmail.com> | 2016-09-04 18:18:37 +0200 |
---|---|---|
committer | Thierry Volpiatto <thierry.volpiatto@gmail.com> | 2016-09-04 18:18:37 +0200 |
commit | 7d1b2917a341dddf2a2c7daded33dfbeda6eb9d7 (patch) | |
tree | b78886ca6c1b1e0a62de27cad30d845f8ad505f2 /helm-lib.el | |
parent | c8f1560e4ac03434964acb34a21534d25306e91f (diff) |
Move functions from helm to helm-lib and require accordingly.
* helm-bookmark.el: Require helm-lib
* helm-lib.el: Added some fns from fns and reorder.
(helm-this-command): Moved from helm.
(helm-append-at-nth): Same.
(helm-current-line-contents): Moved to right section.
* helm-mode.el: require helm-lib.
Diffstat (limited to 'helm-lib.el')
-rw-r--r-- | helm-lib.el | 48 |
1 files changed, 45 insertions, 3 deletions
diff --git a/helm-lib.el b/helm-lib.el index d829faac..ba343219 100644 --- a/helm-lib.el +++ b/helm-lib.el @@ -104,6 +104,33 @@ When only `add-text-properties' is available APPEND is ignored." symbols) ,@body)) +;;; Command loop helper +;; +(defun helm-this-command () + "Returns the actual command in action. +Like `this-command' but return the real command, +and not `exit-minibuffer' or other unwanted functions." + (cl-loop with bl = '(helm-maybe-exit-minibuffer + helm-confirm-and-exit-minibuffer + helm-exit-minibuffer + exit-minibuffer) + for count from 1 to 50 + for btf = (backtrace-frame count) + for fn = (cl-second btf) + if (and + ;; In some case we may have in the way an + ;; advice compiled resulting in byte-code, + ;; ignore it (Issue #691). + (symbolp fn) + (commandp fn) + (not (memq fn bl))) + return fn + else + if (and (eq fn 'call-interactively) + (> (length btf) 2)) + return (cadr (cdr btf)))) + + ;;; Iterators ;; (defun helm-iter-list (seq) @@ -167,9 +194,6 @@ of `cl-return' is possible to exit the loop." (progn ,@(cdr clause1)) (helm-acond ,@(cdr clauses)))))))) -(defun helm-current-line-contents () - "Current line string without properties." - (buffer-substring-no-properties (point-at-bol) (point-at-eol))) ;;; Fuzzy matching routines ;; @@ -403,6 +427,20 @@ ARGS is (cand1 cand2 ...) or ((disp1 . real1) (disp2 . real2) ...) collect (cons (car arg) (funcall function (cdr arg))) else collect (funcall function arg))) + +(defun helm-append-at-nth (seq elm index) + "Append ELM at INDEX in SEQ." + (let ((len (length seq))) + (cond ((> index len) (setq index len)) + ((< index 0) (setq index 0))) + (if (zerop index) + (append elm seq) + (cl-loop for i in seq + for count from 1 collect i + when (= count index) + if (listp elm) append elm + else collect elm)))) + ;;; Strings processing. ;; @@ -465,6 +503,10 @@ Add spaces at end if needed to reach WIDTH when STR is shorter than WIDTH." "Quote whitespace, if some, in string CANDIDATE." (replace-regexp-in-string " " "\\\\ " candidate)) +(defun helm-current-line-contents () + "Current line string without properties." + (buffer-substring-no-properties (point-at-bol) (point-at-eol))) + ;;; Symbols routines ;; |