Function: makefile-fill-paragraph

makefile-fill-paragraph is a byte-compiled function defined in make-mode.el.gz.

Signature

(makefile-fill-paragraph JUSTIFY)

Documentation

Function used for fill-paragraph-function in Makefile mode.

Fill comments, backslashed lines, and variable definitions specially.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/make-mode.el.gz
;; Filling

(defun makefile-fill-paragraph (_justify)
  "Function used for `fill-paragraph-function' in Makefile mode.
Fill comments, backslashed lines, and variable definitions specially."
  (save-excursion
    (beginning-of-line)
    (cond
     ((looking-at "^[ \t]*#+\\s-*")
      ;; Found a comment.  Return nil to let normal filling take place.
      nil)

     ;; Must look for backslashed-region before looking for variable
     ;; assignment.
     ((or (eq (char-before (line-end-position 1)) ?\\)
	  (eq (char-before (line-end-position 0)) ?\\))
      ;; A backslash region.  Find beginning and end, remove
      ;; backslashes, fill, and then reapply backslashes.
      (end-of-line)
      (let ((beginning
	     (save-excursion
	       (end-of-line 0)
	       (while (= (preceding-char) ?\\)
		 (end-of-line 0))
	       ;; Maybe we hit bobp, in which case we are not at EOL.
	       (if (eolp)
		   (1+ (point))
                 (point))))
	    (end
	     (save-excursion
	       (while (and (= (preceding-char) ?\\)
			   (not (eobp)))
		 (end-of-line 2))
	       (point))))
	(save-restriction
	  (narrow-to-region beginning end)
	  (makefile-backslash-region (point-min) (point-max) t)
	  ;; Backslashed newlines are marked as punctuation, so when
	  ;; fill-delete-newlines turns the LF into SPC, we end up with spaces
	  ;; which back-to-indentation (called via fill-newline ->
	  ;; fill-indent-to-left-margin -> indent-line-to) thinks are real code
	  ;; (bug#13179).
          (remove-text-properties (point-min) (point-max) '(syntax-table nil))
	  (let ((fill-paragraph-function nil)
                ;; Adjust fill-column to allow space for the backslash.
                (fill-column (- fill-column 1)))
	    (fill-paragraph nil))
	  (makefile-backslash-region (point-min) (point-max) nil)
	  (goto-char (point-max))
	  (if (< (skip-chars-backward "\n") 0)
	      (delete-region (point) (point-max)))))
      ;; Return non-nil to indicate it's been filled.
      t)

     ((looking-at makefile-macroassign-regex)
      ;; Have a macro assign.  Fill just this line, and then backslash
      ;; resulting region.
      (save-restriction
	(narrow-to-region (point) (line-beginning-position 2))
	(let ((fill-paragraph-function nil)
              ;; Adjust fill-column to allow space for the backslash.
              (fill-column (- fill-column 1)))
	  (fill-paragraph nil))
	(makefile-backslash-region (point-min) (point-max) nil))
      ;; Return non-nil to indicate it's been filled.
      t)

     (t
      ;; Return non-nil so we don't fill anything else.
      t))))