The misc-commands
package defines a function called goto-longest-line
. Using this function, we can define a function that sets org-ascii-text-width
to the length of the longest line in the current buffer:
(defun org-set-ascii-text-width ()
(save-excursion (setq org-ascii-text-width
(cadr (goto-longest-line (point-min) (point-max))))))
To make sure org-ascii-text-width
gets updated every time you save an org-mode
buffer, add it to before-save-hook
:
(add-hook 'before-save-hook
(lambda () (if (eq major-mode 'org-mode)
(org-set-ascii-text-width))))
misc-commands
is available in MELPA and can be package-install
ed (after adding MELPA to the list of package archives for the Emacs Package Manager).
If you don't want to install the package I guess you could also head over here, grab the goto-longest-line
function and add it to your .emacs
(along with a comment that mentions the original author, of course).