aggressive-fill-paragraph-mode
aggressive-fill-paragraph-mode copied to clipboard
Try to set the various adaptive-fill regexs/functions so that bulleted lists in comments are handled correctly
This has turned out to be quite hard, so I need to try again later.
Useful links:
- http://emacs.stackexchange.com/a/9449/237
- http://stackoverflow.com/questions/15176496/filling-markdown-style-list-items-with-hanging-indentation-in-emacs
Scratch code:
(defun my-adaptive-fill-function ()
"Return prefix for filling paragraph or nil if not determined."
(cond
;; ;; List item inside blockquote
;; ((looking-at "^[ \t]*>[ \t]*\\([0-9]+\\.\\|[*+-]\\)[ \t]+")
;; (replace-regexp-in-string
;; "[0-9\\.*+-]" " " (match-string-no-properties 0)))
;; ;; Blockquote
;; ((looking-at "^[ \t]*>[ \t]*")
;; (match-string-no-properties 0))
;; List items
((looking-at (concat "^\\(" comment-start-skip "[ \t]*\\)\\([0-9]+\\.\\|[\\*\\+-]\\)\\([ \t]+\\)"))
(concat (match-string-no-properties 0)
(make-string (length (match-string-no-properties 1)) ?\ )
(match-string-no-properties 2)))
;; No match
(t nil)))
;; Paragraph filling in text-mode.
(set (make-local-variable 'paragraph-start)
(concat "\\s-*$\\|" comment-start-skip "[ \t]*[*+-] \\|" comment-start-skip "[ \t]*[0-9]+\\.[ \t]\\|[ \t]*: "))
(set (make-local-variable 'paragraph-separate)
(concat comment-start-skip "\\(?:\\s-*\\|.* \\)$"))
(set (make-local-variable 'adaptive-fill-first-line-regexp)
(concat comment-start-skip "\\`[ \t]*>[ \t]*?\\'"))
(set (make-local-variable 'adaptive-fill-function)
'my-adaptive-fill-function)
;; (make-local-variable 'adaptive-fill-regexp)
;; (set 'adaptive-fill-regexp (concat comment-start-skip adaptive-fill-regexp))