unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* problems with auto-fill-mode
@ 2021-01-30 16:36 jai-bholeki
  2021-01-30 16:54 ` jai-bholeki
  0 siblings, 1 reply; 4+ messages in thread
From: jai-bholeki @ 2021-01-30 16:36 UTC (permalink / raw)
  To: Help Gnu Emacs

I am having a lot of problems on how to set up  auto-fill-mode.

I want to cycle auto-fill of comments, then disable them using
the keybinding "C-c q".

Have written the following code.

(defun break-comments ()
  "Break lines when they exceed a specific character length."
  (setq-local comment-auto-fill-only-comments t))

(defun fill-break-comments ()
  "Break lines when they exceed a specific character length."
  (setq fill-column 72)
  (setq-local comment-auto-fill-only-comments t)
  (auto-fill-mode 0) )

(defvar dfv-break-comments-state nil)

;; Cycles line breaking tool
(defun cycle-break-comments ()
  "Break comments in programming languages."
  (interactive)

  (pcase dfv-break-comments-state
    ;;
    (1 (setq-local comment-auto-fill-only-comments nil)
       (auto-fill-mode 0)
       (setq dfv-break-comments-state 0)
       (message "%s" "Disable: Break comments"))
    ;;
    (_ (setq fill-column 72)
       (if (not nil dfv-break-comments-state)
	   (add-hook 'prog-mode-hook #'break-comments)
	 (progn
	   (add-hook 'sh-mode-hook          #'break-comments)
	   (add-hook 'fortran-mode-hook     #'break-comments)
	   (add-hook 'emacs-lisp-mode-hook  #'break-comments)
	   (add-hook 'c-mode-hook           #'break-comments)
	   (add-hook 'c++-mode-hook         #'break-comments)
           (add-hook 'awk-mode-hook         #'break-comments)
	   (add-hook 'R-mode-hook           #'break-comments)
	   (add-hook 'octave-mode-hook      #'break-comments)
	   ;;
	   (add-hook 'texinfo-mode-hook  #'break-comments)
	   (add-hook 'text-mode-hook     #'break-comments))
	 (auto-fill-mode))
       ;;
       (setq dfv-break-comments-state 1)
       (message "%s" "Break comments using prog-mode-hook")) )

  ;; Break comments using auto-fill
  (global-set-key (kbd "C-c q") #'cycle-break-comments) )








^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: problems with auto-fill-mode
  2021-01-30 16:36 problems with auto-fill-mode jai-bholeki
@ 2021-01-30 16:54 ` jai-bholeki
  2021-01-30 17:04   ` moasenwood--- via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 4+ messages in thread
From: jai-bholeki @ 2021-01-30 16:54 UTC (permalink / raw)
  To: jai-bholeki; +Cc: Help Gnu Emacs

Does it matter which expression to call first.

 (setq fill-column 72)
 (auto-fill-mode)

or

 (auto-fill-mode)
 (setq fill-column 72)


> Sent: Sunday, January 31, 2021 at 4:36 AM
> From: jai-bholeki@gmx.com
> To: "Help Gnu Emacs" <help-gnu-emacs@gnu.org>
> Subject: problems with auto-fill-mode
>
> I am having a lot of problems on how to set up  auto-fill-mode.
>
> I want to cycle auto-fill of comments, then disable them using
> the keybinding "C-c q".
>
> Have written the following code.
>
> (defun break-comments ()
>   "Break lines when they exceed a specific character length."
>   (setq-local comment-auto-fill-only-comments t))
>
> (defun fill-break-comments ()
>   "Break lines when they exceed a specific character length."
>   (setq fill-column 72)
>   (setq-local comment-auto-fill-only-comments t)
>   (auto-fill-mode 0) )
>
> (defvar dfv-break-comments-state nil)
>
> ;; Cycles line breaking tool
> (defun cycle-break-comments ()
>   "Break comments in programming languages."
>   (interactive)
>
>   (pcase dfv-break-comments-state
>     ;;
>     (1 (setq-local comment-auto-fill-only-comments nil)
>        (auto-fill-mode 0)
>        (setq dfv-break-comments-state 0)
>        (message "%s" "Disable: Break comments"))
>     ;;
>     (_ (setq fill-column 72)
>        (if (not nil dfv-break-comments-state)
> 	   (add-hook 'prog-mode-hook #'break-comments)
> 	 (progn
> 	   (add-hook 'sh-mode-hook          #'break-comments)
> 	   (add-hook 'fortran-mode-hook     #'break-comments)
> 	   (add-hook 'emacs-lisp-mode-hook  #'break-comments)
> 	   (add-hook 'c-mode-hook           #'break-comments)
> 	   (add-hook 'c++-mode-hook         #'break-comments)
>            (add-hook 'awk-mode-hook         #'break-comments)
> 	   (add-hook 'R-mode-hook           #'break-comments)
> 	   (add-hook 'octave-mode-hook      #'break-comments)
> 	   ;;
> 	   (add-hook 'texinfo-mode-hook  #'break-comments)
> 	   (add-hook 'text-mode-hook     #'break-comments))
> 	 (auto-fill-mode))
>        ;;
>        (setq dfv-break-comments-state 1)
>        (message "%s" "Break comments using prog-mode-hook")) )
>
>   ;; Break comments using auto-fill
>   (global-set-key (kbd "C-c q") #'cycle-break-comments) )
>
>
>
>
>
>
>



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: problems with auto-fill-mode
  2021-01-30 16:54 ` jai-bholeki
@ 2021-01-30 17:04   ` moasenwood--- via Users list for the GNU Emacs text editor
  2021-01-30 17:14     ` jai-bholeki
  0 siblings, 1 reply; 4+ messages in thread
From: moasenwood--- via Users list for the GNU Emacs text editor @ 2021-01-30 17:04 UTC (permalink / raw)
  To: help-gnu-emacs

jai-bholeki wrote:

> Does it matter which expression to call first.
>
>  (setq fill-column 72)
>  (auto-fill-mode)
>
> or
>
>  (auto-fill-mode)
>  (setq fill-column 72)

No, because the mode uses that variable setting every time
it fills.

But the top version looks better and makes more sense: first
set it up, then enable.

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: problems with auto-fill-mode
  2021-01-30 17:04   ` moasenwood--- via Users list for the GNU Emacs text editor
@ 2021-01-30 17:14     ` jai-bholeki
  0 siblings, 0 replies; 4+ messages in thread
From: jai-bholeki @ 2021-01-30 17:14 UTC (permalink / raw)
  To: moasenwood; +Cc: help-gnu-emacs


> Sent: Sunday, January 31, 2021 at 5:04 AM
> From: "moasenwood--- via Users list for the GNU Emacs text editor" <help-gnu-emacs@gnu.org>
> To: help-gnu-emacs@gnu.org
> Subject: Re: problems with auto-fill-mode
>
> jai-bholeki wrote:
>
> > Does it matter which expression to call first.
> >
> >  (setq fill-column 72)
> >  (auto-fill-mode)
> >
> > or
> >
> >  (auto-fill-mode)
> >  (setq fill-column 72)
>
> No, because the mode uses that variable setting every time
> it fills.
>
> But the top version looks better and makes more sense: first
> set it up, then enable.

I would also think that setting "comment-auto-fill-only-comments"
should also be set before enable.

(setq fill-column 72)
(setq-local comment-auto-fill-only-comments t)
(auto-fill-mode)

What about add-hook for auto-fill comments for specific files?

(defun break-comments-din ()
  "Break lines when they exceed a specific character length."
  (setq-local comment-auto-fill-only-comments t))

(add-hook 'sh-mode-hook #'break-comments-din)


> --
> underground experts united
> http://user.it.uu.se/~embe8573
> https://dataswamp.org/~incal
>
>
>



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-01-30 17:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-01-30 16:36 problems with auto-fill-mode jai-bholeki
2021-01-30 16:54 ` jai-bholeki
2021-01-30 17:04   ` moasenwood--- via Users list for the GNU Emacs text editor
2021-01-30 17:14     ` jai-bholeki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).