Skip to content

Instantly share code, notes, and snippets.

@syohex
Created May 2, 2016 10:56
Show Gist options
  • Save syohex/b5f9bf829e0f5835a7e82cb078c755d0 to your computer and use it in GitHub Desktop.
Save syohex/b5f9bf829e0f5835a7e82cb078c755d0 to your computer and use it in GitHub Desktop.
Support narrow region in swoop.el
diff --git a/swoop-lib.el b/swoop-lib.el
index d95459c..98cfbdd 100644
--- a/swoop-lib.el
+++ b/swoop-lib.el
@@ -369,6 +369,7 @@ swoop-overlay-target-buffer-selection moved."
($point (point))
($point-min (point-min))
($point-max (point-max))
+ ($min-line (save-restriction (widen) (line-number-at-pos $point-min)))
($max-line (line-number-at-pos $point-max))
($max-line-digit (length (number-to-string $max-line)))
($line-format (concat "%0"
@@ -386,7 +387,7 @@ swoop-overlay-target-buffer-selection moved."
(cons
(substring-no-properties
$with-end-break
- (1- (save-excursion (swoop-goto-line (1+ (* $i $by))) (point)))
+ (save-excursion (swoop-goto-line (1+ (* $i $by))) (- (point) $point-min))
(if (>= (* (1+ $i) $by) $max-line)
nil
(1- (save-excursion
@@ -398,6 +399,7 @@ swoop-overlay-target-buffer-selection moved."
("point" $point)
("point-min" $point-min)
("point-max" $point-max)
+ ("min-line" $min-line)
("max-line" $max-line)
("max-line-digit" $max-line-digit)
("line-format" $line-format)
@@ -532,7 +534,7 @@ swoop-overlay-target-buffer-selection moved."
(process-list)))
(defun swoop-async-get-match-lines-list
- ($query $from $line-format $line-face $buf &optional $pre-select $match-beginning)
+ ($query $from $line-format $min-line $line-face $buf &optional $pre-select $match-beginning)
"Distributed processing by async.el"
;; Prevent "Odd length text property list" error
(setq vc-handled-backends nil)
@@ -600,7 +602,7 @@ swoop-overlay-target-buffer-selection moved."
(buffer-substring (point) (1+ (point-at-eol)))
'line-prefix
(propertize
- (format $line-format $line-num)
+ (format $line-format (1- (+ $line-num $min-line)))
'face $line-face)
'swl $line-num)
$lines))))
diff --git a/swoop.el b/swoop.el
index 8b9c5b3..dadeccf 100644
--- a/swoop.el
+++ b/swoop.el
@@ -496,6 +496,7 @@ Currently c-mode only."
($buf-sep (ht-get $buf-hash "buf-separated"))
($by (ht-get $buf-hash "divide-by"))
($line-format (ht-get $buf-hash "line-format"))
+ ($min-line (ht-get $buf-hash "min-line"))
($buf-sep-id))
(cl-dotimes ($i $tot)
(setq $buf-sep-id (symbol-name (cl-gensym)))
@@ -509,6 +510,7 @@ Currently c-mode only."
(funcall ,swoop-async-get-match-lines-list
',$query ,(* $i $by)
,$line-format
+ ,$min-line
',swoop-n
,$buf
',$pre-select
@@ -527,6 +529,7 @@ Currently c-mode only."
($buf-sep (ht-get $buf-hash "buf-separated"))
($by (ht-get $buf-hash "divide-by"))
($line-format (ht-get $buf-hash "line-format"))
+ ($min-line (ht-get $buf-hash "min-line"))
($buf-sep-id))
(cl-dotimes ($i $tot)
(setq $buf-sep-id (symbol-name (cl-gensym)))
@@ -540,6 +543,7 @@ Currently c-mode only."
(funcall ,swoop-async-get-match-lines-list
',$query ,(* $i $by)
,$line-format
+ ,$min-line
',swoop-n
,$b
',$pre-select
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment