Emacs function to tidy up text files for gopher.
================================================
(defun gopher-format-buffer ()
"Format the current buffer for Gopher:
- Fill paragraphs to 67 columns
- Set encoding to US-ASCII
- Remove non-ASCII characters (with replacements where possible)"
(interactive)
(let ((fill-column 67))
;; Refill all paragraphs
(goto-char (point-min))
(while (not (eobp))
(fill-paragraph nil)
(forward-paragraph)))
;; Show any non-ASCII characters
(let ((non-ascii (delq nil
(mapcar (lambda (c)
(when (> c 127) c))
(string-to-list (buffer-string))))))
(if non-ascii
(message "Warning: Non-ASCII characters found: %s" non-ascii)
(message "Buffer is clean ASCII.")))
;; Set buffer encoding to US-ASCII for saving
(set-buffer-file-coding-system 'us-ascii-unix)
;; Save the buffer
(save-buffer)
(message "Formatted and saved for Gopher."))