From e5795d6bf49cae67fb52fb65395d04b95296934f Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 14 Apr 2021 17:06:59 -0500 Subject: Make `org-return-dwim' auto-fill-mode-aware Added a block at the top of the function to call `auto-fill-function' if it's enabled, and I changed the calls to `newline' to `insert "\n"`, due to ... something. It was having issues figuring out that the new lines were list items I think. I also removed the message part in the middle of the function that I forgot to remove before. --- lisp/acdw-org.el | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'lisp') diff --git a/lisp/acdw-org.el b/lisp/acdw-org.el index 06803d3..c4431ab 100644 --- a/lisp/acdw-org.el +++ b/lisp/acdw-org.el @@ -38,6 +38,12 @@ lists, insert a new item or end the list, with checkbox if appropriate. In tables, insert a new row or end the table." ;; Inspired by John Kitchin: http://kitchingroup.cheme.cmu.edu/blog/2017/04/09/A-better-return-in-org-mode/ (interactive "P") + ;; Auto-fill if enabled + (when auto-fill-function + (if (listp auto-fill-function) + (dolist (func auto-fill-function) + (funcall func)) + (funcall auto-fill-function))) (if default (org-return) (cond @@ -87,10 +93,6 @@ appropriate. In tables, insert a new row or end the table." (org-element-property :contents-end context))) (item-child-p (unpackaged/org-element-descendant-of 'item context))) - (message "(or %S (and %S %S) %S)" - first-item-p - itemp (not emptyp) - item-child-p) ;; The original function from unpackaged just tested the (or ...) test ;; in this cond, in an if. However, that doesn't auto-end nested ;; lists. So I made this form a cond and added the (and...) test in @@ -99,13 +101,13 @@ appropriate. In tables, insert a new row or end the table." ;; for now, it works well enough. (cond ((and itemp emptyp) (delete-region (line-beginning-position) (line-end-position)) - (newline 2)) + (insert "\n\n")) ((or first-item-p (and itemp (not emptyp)) item-child-p) (org-insert-item)) (t (delete-region (line-beginning-position) (line-end-position)) - (newline))))) + (insert "\n"))))) ((when (fboundp 'org-inlinetask-in-task-p) (org-inlinetask-in-task-p)) -- cgit 1.4.1-21-gabe81