Skip to content

Commit

Permalink
Add logging level
Browse files Browse the repository at this point in the history
* iedit-lib.el (iedit-log-level): New defcustom.
(iedit-message): Forward to `message' or do nothing, depending on
`iedit-log-level'.
(iedit-add-occurrence-overlay): Update.
(iedit-next-occurrence): Update.
(iedit-prev-occurrence): Update.
(iedit-goto-first-occurrence): Update.
(iedit-goto-last-occurrence): Update.
(iedit-toggle-buffering): Update.
(iedit-start-buffering): Update.
(iedit-stop-buffering): Update.
  • Loading branch information
abo-abo committed Aug 6, 2016
1 parent 3211c2e commit 5b4d672
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
38 changes: 24 additions & 14 deletions iedit-lib.el
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,16 @@ is not applied to other occurrences when it is true.")
It should be set before occurrence overlay is created.")
(make-local-variable 'iedit-occurrence-keymap)

(defcustom iedit-log-level 1
"Messages with logging level higher than this will be muted."
:type 'integer
:group 'iedit)

(defun iedit-message (log-level format-string &rest args)
"Accounting for LOG-LEVEL, forward to (`message' FORMAT-STRING ARGS)."
(unless (> log-level iedit-log-level)
(apply #'message format-string args)))

(defun iedit-help-for-occurrences ()
"Display `iedit-occurrence-keymap-default'"
(interactive)
Expand Down Expand Up @@ -257,15 +267,15 @@ Return the start position of the new occurrence if successful."
(if (not (if forward
(re-search-forward occurrence-exp bound t)
(re-search-backward occurrence-exp bound t)))
(message "No more matches.")
(iedit-message "No more matches.")
(setq pos (match-beginning 0))
(if (or (iedit-find-overlay-at-point (match-beginning 0) 'iedit-occurrence-overlay-name)
(iedit-find-overlay-at-point (match-end 0) 'iedit-occurrence-overlay-name))
(error "Conflict region"))
(push (iedit-make-occurrence-overlay (match-beginning 0)
(match-end 0))
iedit-occurrences-overlays)
(message "Add one match for \"%s\"." (iedit-printable occurrence-exp))
(iedit-message "Add one match for \"%s\"." (iedit-printable occurrence-exp))
(when iedit-unmatched-lines-invisible
(iedit-show-all)
(iedit-hide-unmatched-lines iedit-occurrence-context-lines))
Expand Down Expand Up @@ -448,7 +458,7 @@ beginning of the buffer."
(if (/= pos (point-max))
(setq iedit-forward-success t)
(if (and iedit-forward-success in-occurrence)
(progn (message "This is the last occurrence.")
(progn (iedit-message 1 "This is the last occurrence.")
(setq iedit-forward-success nil))
(progn
(if (get-char-property (point-min) 'iedit-occurrence-overlay-name)
Expand All @@ -457,7 +467,7 @@ beginning of the buffer."
(point-min)
'iedit-occurrence-overlay-name)))
(setq iedit-forward-success t)
(message "Located the first occurrence."))))
(iedit-message 1 "Located the first occurrence."))))
(when iedit-forward-success
(goto-char pos))))

Expand All @@ -478,14 +488,14 @@ the buffer."
(and (eq (point) (point-min))
in-occurrence))
(if (and iedit-forward-success in-occurrence)
(progn (message "This is the first occurrence.")
(progn (iedit-message 1 "This is the first occurrence.")
(setq iedit-forward-success nil))
(progn
(setq pos (previous-single-char-property-change (point-max) 'iedit-occurrence-overlay-name))
(if (not (get-char-property (- (point-max) 1) 'iedit-occurrence-overlay-name))
(setq pos (previous-single-char-property-change pos 'iedit-occurrence-overlay-name)))
(setq iedit-forward-success t)
(message "Located the last occurrence.")))
(iedit-message 1 "Located the last occurrence.")))
(setq iedit-forward-success t))
(when iedit-forward-success
(goto-char pos))))
Expand All @@ -495,7 +505,7 @@ the buffer."
(interactive)
(goto-char (iedit-first-occurrence))
(setq iedit-forward-success t)
(message "Located the first occurrence."))
(iedit-message 1 "Located the first occurrence."))

(defun iedit-first-occurrence ()
"return the position of the first occurrence."
Expand All @@ -509,7 +519,7 @@ the buffer."
(interactive)
(goto-char (iedit-last-occurrence))
(setq iedit-forward-success t)
(message "Located the last occurrence."))
(iedit-message 1 "Located the last occurrence."))

(defun iedit-last-occurrence ()
"return the position of the last occurrence."
Expand Down Expand Up @@ -677,17 +687,17 @@ be applied to other occurrences when buffering is off."
(if iedit-buffering
(iedit-stop-buffering)
(iedit-start-buffering))
(message (concat "Modification Buffering "
(if iedit-buffering
"started."
"stopped."))))
(iedit-message 0 (concat "Modification Buffering "
(if iedit-buffering
"started."
"stopped."))))

(defun iedit-start-buffering ()
"Start buffering."
(setq iedit-buffering t)
(setq iedit-before-modification-string (iedit-current-occurrence-string))
(setq iedit-before-modification-undo-list buffer-undo-list)
(message "Start buffering editing..."))
(iedit-message 0 "Start buffering editing..."))

(defun iedit-stop-buffering ()
"Stop buffering and apply the modification to other occurrences.
Expand Down Expand Up @@ -718,7 +728,7 @@ modification is not going to be applied to other occurrences."
(iedit-move-conjoined-overlays occurrence))))
(goto-char (+ (overlay-start ov) offset))))))
(setq iedit-buffering nil)
(message "Buffered modification applied.")
(iedit-message 0 "Buffered modification applied.")
(setq iedit-before-modification-undo-list nil))

(defun iedit-move-conjoined-overlays (occurrence)
Expand Down
6 changes: 3 additions & 3 deletions iedit.el
Original file line number Diff line number Diff line change
Expand Up @@ -400,10 +400,10 @@ Keymap used within overlays:
(iedit-start regexp (point-min) (point-max))
;; TODO: reconsider how to avoid the loop in iedit-same-length
(cond ((not iedit-occurrences-overlays)
(message "No matches found for %s" regexp)
(iedit-message 0 "No matches found for %s" regexp)
(iedit-done))
((not (iedit-same-length))
(message "Matches are not the same length.")
(iedit-message 0 "Matches are not the same length.")
(iedit-done)))))

(defun iedit-start (occurrence-regexp beg end)
Expand Down Expand Up @@ -581,7 +581,7 @@ the initial string globally."
(string= iedit-initial-string-local iedit-last-initial-string-global)
(not (string= iedit-last-initial-string-global iedit-last-occurrence-global)))
(iedit-replace-occurrences iedit-last-occurrence-global)
(message "No global modification available.")))
(iedit-message 0 "No global modification available.")))

(defun iedit-toggle-selection ()
"Select or deselect the occurrence under point."
Expand Down

0 comments on commit 5b4d672

Please sign in to comment.