diff --git a/helm-buffers.el b/helm-buffers.el index 4a6ff81b5..e613302f4 100644 --- a/helm-buffers.el +++ b/helm-buffers.el @@ -162,6 +162,21 @@ Only buffer names are fuzzy matched when this is enabled, (defvar helm-buffers-list-cache nil) (defvar helm-buffer-max-len-mode nil) + +(defun helm-buffers-list--init () + ;; Issue #51 Create the list before `helm-buffer' creation. + (setq helm-buffers-list-cache (funcall (helm-attr 'buffer-list))) + (let ((result (cl-loop for b in helm-buffers-list-cache + maximize (length b) into len-buf + maximize (length (with-current-buffer b + (symbol-name major-mode))) + into len-mode + finally return (cons len-buf len-mode)))) + (unless (default-value 'helm-buffer-max-length) + (helm-set-local-variable 'helm-buffer-max-length (car result))) + (unless (default-value 'helm-buffer-max-len-mode) + (helm-set-local-variable 'helm-buffer-max-len-mode (cdr result))))) + (defclass helm-source-buffers (helm-source-sync helm-type-buffer) ((buffer-list :initarg :buffer-list @@ -169,26 +184,9 @@ Only buffer names are fuzzy matched when this is enabled, :custom function :documentation " A function with no arguments to create buffer list.") - (init - :initform - (lambda () - ;; Issue #51 Create the list before `helm-buffer' creation. - (setq helm-buffers-list-cache (funcall (helm-attr 'buffer-list))) - (let ((result (cl-loop for b in helm-buffers-list-cache - maximize (length b) into len-buf - maximize (length (with-current-buffer b - (symbol-name major-mode))) - into len-mode - finally return (cons len-buf len-mode)))) - (unless (default-value 'helm-buffer-max-length) - (helm-set-local-variable 'helm-buffer-max-length (car result))) - (unless (default-value 'helm-buffer-max-len-mode) - ;; If a new buffer is longer that this value - ;; this value will be updated - (helm-set-local-variable 'helm-buffer-max-len-mode (cdr result)))))) + (init :initform 'helm-buffers-list--init) (candidates :initform helm-buffers-list-cache) (matchplugin :initform nil) - ;(nohighlight :initform t) (match :initform 'helm-buffers-match-function) (persistent-action :initform 'helm-buffers-list-persistent-action) (resume :initform (lambda () diff --git a/helm.el b/helm.el index ec4faa9ec..c1859ec28 100644 --- a/helm.el +++ b/helm.el @@ -1508,17 +1508,26 @@ Otherwise, return VALUE itself." (defun helm-set-local-variable (&rest args) "Bind each pair in ARGS locally to `helm-buffer'. + Use this to set local vars before calling helm. + +When used from an init or update function +(i.e when `helm-force-update' is running) the variables are set +using `make-local-variable' within the `helm-buffer'. + Usage: helm-set-local-variable ([VAR VALUE]...) Just like `setq' except that the vars are not set sequentially. -IOW Don't use VALUE of previous VAR to eval the VALUE of next VAR. -When helm is alive use `make-local-variable' as usual on `helm-buffer'. +IOW Don't use VALUE of previous VAR to set the VALUE of next VAR. \(fn VAR VALUE ...)" - (setq helm--local-variables - (append (cl-loop for i on args by #'cddr - collect (cons (car i) (cadr i))) - helm--local-variables))) + (if helm-force-updating-p + (with-helm-buffer + (cl-loop for i on args by #'cddr + do (set (make-local-variable (car i)) (cadr i)))) + (setq helm--local-variables + (append (cl-loop for i on args by #'cddr + collect (cons (car i) (cadr i))) + helm--local-variables)))) (defun helm-make-actions (&rest args) "Build an alist with (NAME . ACTION) elements with each pairs in ARGS.