Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
1. use string returned by (mm/master-substring) as occurrence if ther…
…e is no active region.
  • Loading branch information
Ken Wu committed Jan 13, 2012
1 parent 5a747d2 commit ddc2bee
Showing 1 changed file with 24 additions and 25 deletions.
49 changes: 24 additions & 25 deletions mark-more-like-this.el
Expand Up @@ -50,58 +50,57 @@
With negative ARG, delete the last one instead.
With zero ARG, skip the last one and mark next."
(interactive "p")
(if (not (region-active-p))
(error "Mark a region to match first."))
(unless (or (region-active-p)
mm/master)
(error "Mark a region to match first."))
(if (< arg 0)
(mm/remove-mirror (mm/furthest-mirror-after-master)))
(if (>= arg 0)
(let* ((start (region-beginning))
(end (region-end))
(length (- end start)))
(if (null mm/master)
(mm/create-master start end))
(save-excursion
(progn
(when (null mm/master)
(mm/create-master (region-beginning) (region-end)))

(save-excursion
(goto-char (mm/last-overlay-end))
(if (= arg 0)
(mm/remove-mirror (mm/furthest-mirror-after-master)))
(let ((case-fold-search nil))
(search-forward (mm/master-substring)))
(mm/add-mirror (- (point) length) (point))))))
(mm/add-mirror (- (point) (length (mm/master-substring))) (point))))))

(defun mark-previous-like-this (arg)
"Find and mark the previous part of the buffer matching the currently active region
With negative ARG, delete the last one instead.
With zero ARG, skip the last one and mark previous."
(interactive "p")
(if (not (region-active-p))
(error "Mark a region to match first."))
(unless (or (region-active-p)
mm/master)
(error "Mark a region to match first."))
(if (< arg 0)
(mm/remove-mirror (mm/furthest-mirror-before-master)))
(if (>= arg 0)
(let* ((start (region-beginning))
(end (region-end))
(length (- end start)))
(if (null mm/master)
(mm/create-master start end))
(save-excursion
(progn
(when (null mm/master)
(mm/create-master (region-beginning) (region-end)))

(save-excursion
(goto-char (mm/first-overlay-start))
(if (= arg 0)
(mm/remove-mirror (mm/furthest-mirror-before-master)))
(let ((case-fold-search nil))
(search-backward (mm/master-substring)))
(mm/add-mirror (point) (+ (point) length))))))
(mm/add-mirror (point) (+ (point) (length (mm/master-substring))))))))

(defun mark-more-like-this (arg)
"Marks next part of buffer that matches the currently active region ARG times.
Given a negative ARG it searches backwards instead."
(interactive "p")
(if (not (region-active-p))
(error "Mark a region to match first."))
(let ((start (region-beginning))
(end (region-end)))
(if (> arg 0)
(dotimes (i arg) (mark-next-like-this 1))
(dotimes (i (- arg)) (mark-previous-like-this 1)))))
(unless (or (region-active-p)
mm/master)
(error "Mark a region to match first."))
(if (> arg 0)
(dotimes (i arg) (mark-next-like-this 1))
(dotimes (i (- arg)) (mark-previous-like-this 1))))

(provide 'mark-more-like-this)

Expand Down

0 comments on commit ddc2bee

Please sign in to comment.