help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cycle Auto-Fill


From: Ergus
Subject: Re: Cycle Auto-Fill
Date: Sat, 5 Dec 2020 15:39:16 +0100

Hi Christopher:

I am not a big lisper, but I had a similar code. I modified yours to
look similar in case you find anything interesting on it

```
(defvar gungadin-auto-fill-cycle 0)

(defun gungadin-auto-fill-cycle ()
  "Cycles Auto Fill.

Automatically breaks lines that get beyond variable fill-column."
  (interactive)

  (pcase gungadin-auto-fill-cycle
    (0
     (message "Auto Fill Comments Only")
     (setq-local comment-auto-fill-only-comments t)
     (auto-fill-mode 1))
    (1
     (message "Auto Fill Buffer")
     (setq-local comment-auto-fill-only-comments nil))
    (2
     (message "Disable Auto Fill")
     (auto-fill-mode 0)))
  (setq gungadin-auto-fill-cycle (% (1+ gungadin-auto-fill-cycle) 3)))
```


On Sat, Dec 05, 2020 at 02:25:06PM +0100, Christopher Dimech wrote:
Have written the following function to use one key binding
to cycle auto-fill (only-comments, whole-buffer, disable)

Who would like to criticise this little bugger?

(defun gungadin-auto-fill-cycle ()
  "Cycles Auto Fill.  Automatically breaks lines that get beyond
variable fill-column."
  (interactive)
  (unless (get 'gungadin-auto-fill-cycle 'state)
     (put 'gungadin-auto-fill-cycle 'state 1))

  (setq n (get 'gungadin-auto-fill-cycle 'state))

  (when (= n 1)
     (message "Auto Fill Comments Only")
     (set (make-local-variable 'comment-auto-fill-only-comments) t)
     (auto-fill-mode 1)
     (put 'gungadin-auto-fill-cycle 'state 2))
  (when (= n 2)
     (message "Auto Fill Buffer")
     (set (make-local-variable 'comment-auto-fill-only-comments) nil)
     (put 'gungadin-auto-fill-cycle 'state 3))
  (when (= n 3)
     (message "Disable Auto Fill")
     (auto-fill-mode 0)
     (put 'gungadin-auto-fill-cycle 'state 1)) )

(global-set-key (kbd "H-a") #'gungadin-auto-fill-cycle)



---------------------
Christopher Dimech
General Administrator - Naiad Informatics - GNU Project (Geocomputation)
- Geophysical Simulation
- Geological Subsurface Mapping
- Disaster Preparedness and Mitigation
- Natural Resource Exploration and Production
- Free Software Advocacy




reply via email to

[Prev in Thread] Current Thread [Next in Thread]