]> code.delx.au - gnu-emacs-elpa/blobdiff - swiper.el
Fix due to visual-line-mode weirdness
[gnu-emacs-elpa] / swiper.el
index eec743461e571996de01381d5b102a5d6cf8ef3c..593f7633549171a798f6fd11d9ea1cc79ba4f79c 100644 (file)
--- a/swiper.el
+++ b/swiper.el
     (let* ((enable-recursive-minibuffers t)
            (from (ivy--regex ivy-text))
            (to (query-replace-read-to from "Query replace" t)))
-      (delete-minibuffer-contents)
-      (ivy-set-action (lambda (_)
-                        (with-ivy-window
-                          (move-beginning-of-line 1)
-                          (perform-replace from to
-                                           t t nil))))
       (swiper--cleanup)
-      (exit-minibuffer))))
+      (ivy-exit-with-action
+       (lambda (_)
+         (with-ivy-window
+           (move-beginning-of-line 1)
+           (perform-replace from to
+                            t t nil)))))))
 
 (defvar avy-background)
 (defvar avy-all-windows)
     (error "multiple-cursors isn't installed"))
   (let ((cands (nreverse ivy--old-cands)))
     (unless (string= ivy-text "")
-      (ivy-set-action
+      (ivy-exit-with-action
        (lambda (_)
          (let (cand)
            (while (setq cand (pop cands))
              (swiper--action cand)
              (when cands
                (mc/create-fake-cursor-at-point))))
-         (multiple-cursors-mode 1)))
-      (setq ivy-exit 'done)
-      (exit-minibuffer))))
+         (multiple-cursors-mode 1))))))
 
 (defun swiper-recenter-top-bottom (&optional arg)
   "Call (`recenter-top-bottom' ARG)."
                                  occur-edit-mode
                                  bongo-mode
                                  eww-mode
+                                 twittering-mode
                                  w3m-mode)))
     (unless (> (buffer-size) 100000)
       (if (fboundp 'font-lock-ensure)
 (defvar swiper-use-visual-line nil
   "When non-nil, use `line-move' instead of `forward-line'.")
 
+(declare-function outline-show-all "outline")
+
 (defun swiper--candidates (&optional numbers-width)
   "Return a list of this buffer lines.
 
 NUMBERS-WIDTH, when specified, is used for line numbers width
 spec, instead of calculating it as the log of the buffer line
 count."
-  (setq swiper-use-visual-line
-        (and (not (eq major-mode 'org-mode))
-             visual-line-mode
-             (< (buffer-size) 20000)))
+  (if (and visual-line-mode
+           ;; super-slow otherwise
+           (< (buffer-size) 20000))
+      (progn
+        (when (eq major-mode 'org-mode)
+          (require 'outline)
+          (if (fboundp 'outline-show-all)
+              (outline-show-all)
+            (show-all)))
+        (setq swiper-use-visual-line t))
+    (setq swiper-use-visual-line nil))
   (let ((n-lines (count-lines (point-min) (point-max))))
     (unless (zerop n-lines)
       (setq swiper--width (or numbers-width
@@ -273,13 +280,19 @@ count."
                         " "
                         (replace-regexp-in-string
                          "\t" "    "
-                         (buffer-substring
-                          (point)
-                          (if swiper-use-visual-line
+                         (if swiper-use-visual-line
+                             (buffer-substring
                               (save-excursion
-                                (end-of-visual-line)
+                                (beginning-of-visual-line)
                                 (point))
+                              (save-excursion
+                                (end-of-visual-line)
+                                (point)))
+                           (buffer-substring
+                            (point)
                             (line-end-position)))))))
+              (when (eq major-mode 'twittering-mode)
+                (remove-text-properties 0 (length str) '(field) str))
               (put-text-property 0 1 'display
                                  (format swiper--format-spec
                                          (cl-incf line-number))
@@ -341,27 +354,29 @@ When non-nil, INITIAL-INPUT is the initial search pattern."
         (plist-get (text-properties-at (point)) 'face))
   (let ((candidates (swiper--candidates))
         (preselect
-         (if (bound-and-true-p visual-line-mode)
-             (concat " " (buffer-substring-no-properties
-                          (line-beginning-position)
-                          (line-end-position)))
+         (if swiper-use-visual-line
+             (count-screen-lines
+              (point-min)
+              (save-excursion (beginning-of-visual-line) (point)))
            (1- (line-number-at-pos))))
-        (minibuffer-allow-text-properties t))
+        (minibuffer-allow-text-properties t)
+        res)
     (unwind-protect
-         (ivy-read
-          "Swiper: "
-          candidates
-          :initial-input initial-input
-          :keymap swiper-map
-          :preselect preselect
-          :require-match t
-          :update-fn #'swiper--update-input-ivy
-          :unwind #'swiper--cleanup
-          :action #'swiper--action
-          :re-builder #'swiper--re-builder
-          :history 'swiper-history
-          :caller 'swiper)
-      (when (null ivy-exit)
+         (setq res
+               (ivy-read
+                "Swiper: "
+                candidates
+                :initial-input initial-input
+                :keymap swiper-map
+                :preselect preselect
+                :require-match t
+                :update-fn #'swiper--update-input-ivy
+                :unwind #'swiper--cleanup
+                :action #'swiper--action
+                :re-builder #'swiper--re-builder
+                :history 'swiper-history
+                :caller 'swiper))
+      (unless res
         (goto-char swiper--opoint)))))
 
 (defun swiper-toggle-face-matching ()
@@ -509,8 +524,9 @@ WND, when specified is the window."
       (swiper--ensure-visible)
       (when (/= (point) swiper--opoint)
         (unless (and transient-mark-mode mark-active)
-          (push-mark swiper--opoint t)
-          (message "Mark saved where search started"))))))
+          (when (eq ivy-exit 'done)
+            (push-mark swiper--opoint t)
+            (message "Mark saved where search started")))))))
 
 ;; (define-key isearch-mode-map (kbd "C-o") 'swiper-from-isearch)
 (defun swiper-from-isearch ()