Skip to content

Instantly share code, notes, and snippets.

@tam17aki
Last active December 25, 2015 07:49
Show Gist options
  • Save tam17aki/6941835 to your computer and use it in GitHub Desktop.
Save tam17aki/6941835 to your computer and use it in GitHub Desktop.
(cl-defun helm-moccur-action (candidate
&optional (method (quote buffer)) mark)
"Jump to CANDIDATE with METHOD.
arg METHOD can be one of buffer, buffer-other-window, buffer-other-frame."
(require 'helm-grep)
(let* ((split (helm-grep-split-line candidate))
(buf (car split))
(lineno (string-to-number (nth 1 split)))
(split-pat (if helm-occur-match-plugin-mode
(helm-mp-split-pattern helm-pattern)
(list helm-pattern)))
;; for helm-migemo
(search-func (if (featurep 'migemo)
'migemo-forward
're-search-forward)))
(cl-case method
(buffer (switch-to-buffer buf))
(buffer-other-window (switch-to-buffer-other-window buf))
(buffer-other-frame (switch-to-buffer-other-frame buf)))
(helm-goto-line lineno)
;; Move point to the nearest matching regexp from bol.
(cl-loop for reg in split-pat
when (save-excursion
(funcall search-func reg (point-at-eol) t))
collect (match-beginning 0) into pos-ls
finally (goto-char (apply #'min pos-ls)))
(when mark
(set-marker (mark-marker) (point))
(push-mark (point) 'nomsg))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment