branch: elpa/helm
commit e98ae93a5012c62e69064a60df557b9acd5e0515
Author: Thierry Volpiatto <thie...@posteo.net>
Commit: Thierry Volpiatto <thie...@posteo.net>

    Ensure current-buffer source is always on top in helm-occur
---
 helm-occur.el | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/helm-occur.el b/helm-occur.el
index 931ecf5b4a..97305d9dc7 100644
--- a/helm-occur.el
+++ b/helm-occur.el
@@ -176,16 +176,17 @@ This happen only in `helm-source-occur' which is always 
related to
             closest beg end)
         (while-no-input
           (goto-char (point-min))
-          (if (string= name "Helm occur")
-              (setq beg (point)
-                    end (point-max))
-            (helm-awhile (helm-get-next-header-pos)
-              (when (string= name (buffer-substring-no-properties
-                                   (pos-bol) (pos-eol)))
-                (forward-line 1)
-                (setq beg (point)
-                      end (or (helm-get-next-header-pos) (point-max)))
-                (cl-return))))
+          (cond ((string= name "Helm occur")
+                 (setq beg (point)
+                       end (point-max)))
+                ;; The source corresponding to helm-current-buffer should be
+                ;; always on top, so no need to search for it by looping in
+                ;; helm-buffer.
+                ((string= name (buffer-substring-no-properties
+                                (pos-bol) (pos-eol)))
+                 (forward-line 1)
+                 (setq beg (point)
+                       end (or (helm-get-next-header-pos) (point-max)))))
           (save-excursion
             (when (and beg end)
               (goto-char beg)
@@ -410,8 +411,9 @@ helm-occur will start immediately with DEFAULT as INPUT.
 Always prefer using DEFAULT instead of INPUT, they have the same effect but
 DEFAULT keep the minibuffer empty, allowing the user to write immediately
 without having to delete its contents before."
-  (let* ((curbuf (current-buffer))
-         (bufs (if helm-occur-always-search-in-current
+  (let* ((curbuf (get-buffer helm-current-buffer))
+         (bufs (if (or helm-occur-always-search-in-current
+                       (memql curbuf buffers))
                    (cons curbuf (remove curbuf buffers))
                  buffers))
          (helm-sources-using-default-as-input
@@ -431,7 +433,7 @@ without having to delete its contents before."
                              (cl-loop for b in bufs collect
                                       (buffer-chars-modified-tick
                                        (get-buffer b))))
-    (when (and helm-occur-always-search-in-current
+    (when (and (eql (car bufs) curbuf)
                helm-occur-keep-closest-position)
       (setq helm-source-occur
             (cl-loop for s in sources

Reply via email to