Function: c-append-backslashes-forward

c-append-backslashes-forward is a byte-compiled function defined in cc-cmds.el.gz.

Signature

(c-append-backslashes-forward TO-MARK COLUMN POINT-POS)

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/cc-cmds.el.gz
(defun c-append-backslashes-forward (to-mark column point-pos)
  (let ((state (parse-partial-sexp (c-point 'bol) (point))))
    (if column
	(while
	    (and
	     (<= (point) to-mark)

	     (let ((start (point)) (inserted nil) end col)
	       (end-of-line)
	       (unless (eq (char-before) ?\\)
		 (insert ?\\)
		 (setq inserted t))
	       (setq state (parse-partial-sexp
			    start (point) nil nil state))
	       (backward-char)
	       (setq col (current-column))

	       ;; Avoid unnecessary changes of the buffer.
	       (cond ((and (not inserted) (nth 3 state))
		      ;; Don't realign backslashes in string literals
		      ;; since that would change them.
		      )

		     ((< col column)
		      (delete-region
		       (point)
		       (progn
			 (skip-chars-backward
			  " \t" (if (>= (point) point-pos) point-pos))
			 (point)))
		      (indent-to column))

		     ((and (= col column)
			   (memq (char-before) '(?\  ?\t))))

		     ((progn
			(setq end (point))
			(or (/= (skip-chars-backward
				 " \t" (if (>= (point) point-pos) point-pos))
				-1)
			    (/= (char-after) ?\ )))
		      (delete-region (point) end)
		      (indent-to column 1)))

	       (zerop (forward-line 1)))
	     (bolp)))			; forward-line has funny behavior at eob.

      ;; Make sure there are backslashes with at least one space in
      ;; front of them.
      (while
	  (and
	   (<= (point) to-mark)

	   (let ((start (point)))
	     (end-of-line)
	     (setq state (parse-partial-sexp
			  start (point) nil nil state))

	     (if (eq (char-before) ?\\)
		 (unless (nth 3 state)
		   (backward-char)
		   (unless (and (memq (char-before) '(?\  ?\t))
				(/= (point) point-pos))
		     (insert ?\ )))

	       (if (and (memq (char-before) '(?\  ?\t))
			(/= (point) point-pos))
		   (insert ?\\)
		 (insert ?\  ?\\)))

	     (zerop (forward-line 1)))
	   (bolp))))))			; forward-line has funny behavior at eob.