Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logging level #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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