emacsorphanage / helm-swoop

Efficiently hopping squeezed lines powered by Emacs helm interface
GNU General Public License v3.0
689 stars 55 forks source link

helm-swoop breaks in mu4e-compose buffers due to bad regex #23

Closed stsquad closed 10 years ago

stsquad commented 10 years ago

When I active helm-swoop in my mu4e:compose window I get the following reported:

helm-swoop--keep-nearest-position: Invalid regexp: "Unmatched [ or [^"

Looking at the code:

(defun helm-swoop--keep-nearest-position ()
  (with-helm-window
    (let (($p (point-min)) $list $bound
          $nearest-line $target-point
          ($buf (buffer-name (car helm-swoop-last-line-info))))
      (save-excursion
        (goto-char $p)
        (while (if $p (setq $p (re-search-forward (concat "^" $buf "$") nil t)))

I think the re-search-forward is going to break if the buffer name contains any special characters, which in my case it does as it's:

"Re: [Qemu-devel] [PATCH v3 ...<5>"
stsquad commented 10 years ago

This change fixed it but I'm not quite sure what the function was trying to achieve:

(defun helm-swoop--keep-nearest-position ()
  (with-helm-window
    (let (($p (point-min)) $list $bound
          $nearest-line $target-point
          ($buf (buffer-name (car helm-swoop-last-line-info))))
      (save-excursion
        (goto-char $p)
        (while (if $p (setq $p (re-search-forward (concat "^"
  (rx-to-string $buf t) "$") nil t)))
          (when (get-text-property (point-at-bol) 'helm-header)
            (forward-char 1)
            (setq $bound (next-single-property-change (point) 'helm-header))
            (while (re-search-forward "^[0-9]+" $bound t)
              (setq $list (cons
                           (string-to-number (match-string 0))
                           $list)))
            (setq $nearest-line (helm-swoop--nearest-line
                            (cdr helm-swoop-last-line-info)
                            $list))
            (goto-char $p)
            (re-search-forward (concat "^"
                                       (number-to-string $nearest-line)
                                       "\\s-") $bound t)
            (setq $target-point (point))
            (setq $p nil))))
      (when $target-point
        (goto-char $target-point)
        (helm-mark-current-line)
        (if (equal helm-swoop-buffer (buffer-name (current-buffer)))
            (helm-swoop--move-line-action)
          (helm-multi-swoop--move-line-action))))))
ShingoFukuyama commented 10 years ago

Thank you @stsquad, rx-to-string is what it needs to!