Function: checkdoc-autofix-ask-replace

checkdoc-autofix-ask-replace is a byte-compiled function defined in checkdoc.el.gz.

Signature

(checkdoc-autofix-ask-replace START END QUESTION REPLACEWITH &optional COMPLEX)

Documentation

Highlight between START and END and queries the user with QUESTION.

If the user says yes, or if checkdoc-autofix-flag permits, replace the region marked by START and END with REPLACEWITH. If optional flag COMPLEX is non-nil, then we may ask the user a question. See the documentation for checkdoc-autofix-flag for details.

If a section is auto-replaced without asking the user, this function will pause near the fixed code so the user will briefly see what happened.

This function returns non-nil if the text was replaced.

This function will not modify match-data.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/checkdoc.el.gz
(defun checkdoc-autofix-ask-replace (start end question replacewith
					   &optional complex)
  "Highlight between START and END and queries the user with QUESTION.
If the user says yes, or if `checkdoc-autofix-flag' permits, replace
the region marked by START and END with REPLACEWITH.  If optional flag
COMPLEX is non-nil, then we may ask the user a question.  See the
documentation for `checkdoc-autofix-flag' for details.

If a section is auto-replaced without asking the user, this function
will pause near the fixed code so the user will briefly see what
happened.

This function returns non-nil if the text was replaced.

This function will not modify `match-data'."
  (if (and checkdoc-autofix-flag
	   (not (eq checkdoc-autofix-flag 'never)))
      (let ((o (make-overlay start end))
	    (ret nil)
	    (md (match-data)))
	(unwind-protect
	    (progn
	      (overlay-put o 'face 'highlight)
	      (if (or (eq checkdoc-autofix-flag 'automatic)
		      (eq checkdoc-autofix-flag 'automatic-then-never)
		      (and (eq checkdoc-autofix-flag 'semiautomatic)
			   (not complex))
		      (and (or (eq checkdoc-autofix-flag 'query) complex)
			   (y-or-n-p question)))
		  (save-excursion
		    (goto-char start)
		    ;; On the off chance this is automatic, display
		    ;; the question anyway so the user knows what's
		    ;; going on.
		    (if checkdoc-bouncy-flag (message "%s -> done" question))
		    (delete-region start end)
		    (insert-before-markers replacewith)
		    (if checkdoc-bouncy-flag (sit-for 0))
		    (setq ret t)))
	      (delete-overlay o)
	      (set-match-data md))
	  (delete-overlay o)
	  (set-match-data md))
	(if (eq checkdoc-autofix-flag 'automatic-then-never)
	    (setq checkdoc-autofix-flag 'never))
	ret)))