diff options
Diffstat (limited to 'helm-lib.el')
-rw-r--r-- | helm-lib.el | 103 |
1 files changed, 61 insertions, 42 deletions
diff --git a/helm-lib.el b/helm-lib.el index 7b9825be..aa9e5e8c 100644 --- a/helm-lib.el +++ b/helm-lib.el @@ -1,6 +1,6 @@ ;;; helm-lib.el --- Helm routines. -*- lexical-binding: t -*- -;; Copyright (C) 2015 ~ 2019 Thierry Volpiatto <thierry.volpiatto@gmail.com> +;; Copyright (C) 2015 ~ 2020 Thierry Volpiatto <thierry.volpiatto@gmail.com> ;; Author: Thierry Volpiatto <thierry.volpiatto@gmail.com> ;; URL: http://github.com/emacs-helm/helm @@ -32,8 +32,8 @@ (declare-function dired-mark-remembered "dired.el") (declare-function ffap-file-remote-p "ffap.el") (declare-function ffap-url-p "ffap.el") -(declare-function helm-attr "helm.el") -(declare-function helm-attrset "helm.el") +(declare-function helm-get-attr "helm.el") +(declare-function helm-set-attr "helm.el") (declare-function helm-follow-mode-p "helm.el") (declare-function helm-get-current-source "helm.el") (declare-function helm-get-selection "helm.el") @@ -47,6 +47,9 @@ (declare-function org-content "org.el") (declare-function org-mark-ring-goto "org.el") (declare-function org-mark-ring-push "org.el") +(declare-function org-table-p "org-compat.el") +(declare-function org-table-align "org-table.el") +(declare-function org-table-end "org-table.el") (declare-function org-open-at-point "org.el") (declare-function wdired-change-to-dired-mode "wdired.el") (declare-function wdired-do-perm-changes "wdired.el") @@ -392,24 +395,27 @@ available APPEND is ignored." ;;; Command loop helper ;; +(defconst helm-this-command-black-list + '(helm-maybe-exit-minibuffer + helm-confirm-and-exit-minibuffer + helm-exit-minibuffer + exit-minibuffer + helm-M-x)) + (defun helm-this-command () "Return 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 + (cl-loop 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). + ;; ignore it (Bug#691). (symbolp fn) (commandp fn) - (not (memq fn bl))) + (not (memq fn helm-this-command-black-list))) return fn else if (and (eq fn 'call-interactively) @@ -646,9 +652,14 @@ displayed in BUFNAME." (when helm-help-full-frame (delete-other-windows)) (delete-region (point-min) (point-max)) (org-mode) - (org-mark-ring-push) ; Put mark at bob (save-excursion - (funcall insert-content-fn)) + (funcall insert-content-fn) + (goto-char (point-min)) + (while (re-search-forward "^[|]" nil t) + (when (org-table-p t) + (org-table-align) + (goto-char (org-table-end))))) + (org-mark-ring-push) ; Put mark at bob (buffer-disable-undo) (helm-help-event-loop)) (raise-frame hframe) @@ -733,7 +744,7 @@ displayed in BUFNAME." (not (memq fun helm-help-not-interactive-command))) ;; For movement of cursor in help buffer we need to ;; call interactively commands for impaired people - ;; using a synthetizer (#1347). + ;; using a synthetizer (Bug#1347). (call-interactively fun) (funcall fun)))))))) @@ -742,13 +753,17 @@ displayed in BUFNAME." If OVERRIDE is non nil, all bindings associated with FUNCTION are removed and only (KEY . FUNCTION) is kept. +If FUNCTION is nil (KEY . FUNCTION) is not added and removed from +alist if already present. See `helm-help-hkmap' for supported keys and functions." (cl-assert (not (cdr (split-string key))) nil (format "Error: Unsuported key `%s'" key)) (when override (helm-awhile (rassoc function helm-help-hkmap) (setq helm-help-hkmap (delete it helm-help-hkmap)))) - (add-to-list 'helm-help-hkmap `(,key . ,function))) + (helm-aif (and (null function) (assoc key helm-help-hkmap)) + (setq helm-help-hkmap (delete it helm-help-hkmap)) + (and function (add-to-list 'helm-help-hkmap `(,key . ,function))))) ;;; Multiline transformer ;; @@ -784,21 +799,22 @@ See `helm-help-hkmap' for supported keys and functions." ;;; List processing ;; -(defun helm-flatten-list (seq &optional omit-nulls) - "Return a list of all single elements of sublists in SEQ." +(defun helm-flatten-list (seq) + "Return a list of all single elements of sublists in SEQ. + + Example: + (helm-flatten-list '(1 (2 . 3) nil (4 5 (6) 7) 8 (9 . 10))) + => (1 2 3 4 5 6 7 8 9 10)" (let (result) - (cl-labels ((flatten (seq) - (cl-loop - for elm in seq - if (and (or elm - (null omit-nulls)) - (or (atom elm) - (functionp elm) - (and (consp elm) - (cdr elm) - (atom (cdr elm))))) - do (push elm result) - else do (flatten elm)))) + (cl-labels ((flatten + (seq) + (cl-loop for elm in seq + if (consp elm) + do (flatten + (if (atom (cdr elm)) + (list (car elm) (cdr elm)) + elm)) + else do (and elm (push elm result))))) (flatten seq)) (nreverse result))) @@ -854,7 +870,7 @@ hashtable itself." (helm-awhile (helm-basedir (directory-file-name (expand-file-name directory))) ;; Break at root to avoid infloop, root is / or on Windows - ;; C:/ i.e. <volume>:/ (issue #2308). + ;; C:/ i.e. <volume>:/ (Bug#2308). (when (string-match-p "\\`[A-Za-z]?:?/\\'" it) (cl-return nil)) (when (cl-loop for r in black-list @@ -961,6 +977,15 @@ If NAME returns nil the pair is skipped. do (setq name (funcall name)) when name collect (cons name fn))) + +(defun helm-closest-number-in-list (num list) + "Return closest number to NUM found in LIST. +LIST is a list of numbers and NUM a number." + (cl-loop for i in list + for diff = (if (> num i) (- num i) (- i num)) + collect (cons diff i) into res + minimize diff into min + finally return (cdr (assq min res)))) ;;; Strings processing. ;; @@ -1169,8 +1194,8 @@ See `helm-elisp-show-help'." (if name (funcall fun candidate name) (funcall fun candidate))) - ((or (and (helm-attr 'help-running-p) - (string= candidate (helm-attr 'help-current-symbol)))) + ((or (and (helm-get-attr 'help-running-p) + (string= candidate (helm-get-attr 'help-current-symbol)))) (progn ;; When started from a help buffer, ;; Don't kill this buffer as it is helm-current-buffer. @@ -1184,7 +1209,7 @@ See `helm-elisp-show-help'." (if helm--buffer-in-new-frame-p helm-current-buffer helm-persistent-action-window-buffer))) - (helm-attrset 'help-running-p nil)) + (helm-set-attr 'help-running-p nil)) ;; Force running update hook to may be delete ;; helm-persistent-action-display-window, this is done in ;; helm-persistent-action-display-window (the function). @@ -1194,8 +1219,8 @@ See `helm-elisp-show-help'." (if name (funcall fun candidate name) (funcall fun candidate)) - (helm-attrset 'help-running-p t))) - (helm-attrset 'help-current-symbol candidate))) + (helm-set-attr 'help-running-p t))) + (helm-set-attr 'help-current-symbol candidate))) (defun helm-find-function (func) "FUNC is symbol or string." @@ -1261,7 +1286,8 @@ Argument ALIST is an alist of associated major modes." (defun helm-file-name-sans-extension (filename) "Same as `file-name-sans-extension' but remove all extensions." (helm-aif (file-name-sans-extension filename) - ;; Start searching at index 1 for files beginning with a dot (#1335). + ;; Start searching at index 1 for files beginning with a dot + ;; (bug#1335). (if (string-match "\\." (helm-basename it) 1) (helm-file-name-sans-extension it) it))) @@ -1727,7 +1753,6 @@ broken." '(("(\\<\\(with-helm-after-update-hook\\)\\>" 1 font-lock-keyword-face) ("(\\<\\(with-helm-temp-hook\\)\\>" 1 font-lock-keyword-face) ("(\\<\\(with-helm-window\\)\\>" 1 font-lock-keyword-face) - ("(\\<\\(with-helm-quittable\\)\\>" 1 font-lock-keyword-face) ("(\\<\\(with-helm-current-buffer\\)\\>" 1 font-lock-keyword-face) ("(\\<\\(with-helm-buffer\\)\\>" 1 font-lock-keyword-face) ("(\\<\\(with-helm-show-completion\\)\\>" 1 font-lock-keyword-face) @@ -1744,10 +1769,4 @@ broken." (provide 'helm-lib) -;; Local Variables: -;; byte-compile-warnings: (not obsolete) -;; coding: utf-8 -;; indent-tabs-mode: nil -;; End: - ;;; helm-lib ends here |