* Indenting with spaces rather than tabs
@ 2021-01-29 1:26 wael-zwaiter
2021-01-29 2:00 ` moasenwood--- via Users list for the GNU Emacs text editor
2021-01-29 5:25 ` Robert Thorpe
0 siblings, 2 replies; 11+ messages in thread
From: wael-zwaiter @ 2021-01-29 1:26 UTC (permalink / raw)
To: Help Gnu Emacs
Want to indent with spaces rather than tabs and have found the command
(setq-default indent-tabs-mode nil)
But one can also use "M-x untabify".
What should I use for my init file? Am not so sure about using "setq"
rather than "setq-default".
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Indenting with spaces rather than tabs
2021-01-29 1:26 Indenting with spaces rather than tabs wael-zwaiter
@ 2021-01-29 2:00 ` moasenwood--- via Users list for the GNU Emacs text editor
2021-02-01 9:46 ` Philip K.
2021-01-29 5:25 ` Robert Thorpe
1 sibling, 1 reply; 11+ messages in thread
From: moasenwood--- via Users list for the GNU Emacs text editor @ 2021-01-29 2:00 UTC (permalink / raw)
To: help-gnu-emacs
wael-zwaiter wrote:
> Want to indent with spaces rather than tabs and have found
> the command
>
> (setq-default indent-tabs-mode nil)
>
> But one can also use "M-x untabify".
>
> What should I use for my init file?
(defun untab-all ()
(unless (member major-mode '(makefile-gmake-mode
makefile-mode) ) ; exceptions
(untabify (point-min) (point-max)))
nil) ; tell "did not write buffer to disk"
(setq-default tab-width 3)
(setq-default indent-tabs-mode nil)
;; (setq before-save-hook nil)
(defun before-save-hook-f ()
(untab-all)
(delete-trailing-whitespace) )
(add-hook 'before-save-hook #'before-save-hook-)f
--
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Indenting with spaces rather than tabs
2021-01-29 1:26 Indenting with spaces rather than tabs wael-zwaiter
2021-01-29 2:00 ` moasenwood--- via Users list for the GNU Emacs text editor
@ 2021-01-29 5:25 ` Robert Thorpe
2021-01-29 13:04 ` wael-zwaiter
1 sibling, 1 reply; 11+ messages in thread
From: Robert Thorpe @ 2021-01-29 5:25 UTC (permalink / raw)
To: wael-zwaiter; +Cc: help-gnu-emacs
wael-zwaiter@gmx.com writes:
> Want to indent with spaces rather than tabs and have found the command
>
> (setq-default indent-tabs-mode nil)
>
> But one can also use "M-x untabify".
>
> What should I use for my init file? Am not so sure about using "setq"
> rather than "setq-default".
If you set indent-tabs-mode like that then it applies to things that you
edit.
But it does not apply to all of the file. Parts of the file you don't
edit are untouched. Now often this is what you want. If you're working
on a project in a group then you don't really want whitespace changes.
(Though really everyone should be using the same convention for tabs).
On the other hand, untabify deals with the whole file. It changes parts
you have never edited or viewed.
The setq-default part means that you're setting the default value for
buffers. But modes in buffers may over-ride it with a local variable
write. I'm not sure that you need setq-default here.
BR,
Robert Thorpe
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Indenting with spaces rather than tabs
2021-01-29 5:25 ` Robert Thorpe
@ 2021-01-29 13:04 ` wael-zwaiter
2021-01-29 13:10 ` moasenwood--- via Users list for the GNU Emacs text editor
2021-01-30 18:46 ` Robert Thorpe
0 siblings, 2 replies; 11+ messages in thread
From: wael-zwaiter @ 2021-01-29 13:04 UTC (permalink / raw)
To: Robert Thorpe; +Cc: help-gnu-emacs
Can I do as follows, so that tabs are removed when "dfv-untabify-state"
is "true".
(defvar dfv-untabify-state nil)
(defun clean-before-save ()
"Removes trailing spaces and tabs upon exiting"
(delete-trailing-whitespace)
(when (dfv-untabify-state)
(unless (member major-mode '(makefile-gmake-mode makefile-mode))
(untabify (point-min) (point-max))) ))
> Sent: Friday, January 29, 2021 at 5:25 PM
> From: "Robert Thorpe" <rt@robertthorpeconsulting.com>
> To: wael-zwaiter@gmx.com
> Cc: help-gnu-emacs@gnu.org
> Subject: Re: Indenting with spaces rather than tabs
>
> wael-zwaiter@gmx.com writes:
>
> > Want to indent with spaces rather than tabs and have found the command
> >
> > (setq-default indent-tabs-mode nil)
> >
> > But one can also use "M-x untabify".
> >
> > What should I use for my init file? Am not so sure about using "setq"
> > rather than "setq-default".
>
> If you set indent-tabs-mode like that then it applies to things that you
> edit.
>
> But it does not apply to all of the file. Parts of the file you don't
> edit are untouched. Now often this is what you want. If you're working
> on a project in a group then you don't really want whitespace changes.
> (Though really everyone should be using the same convention for tabs).
>
> On the other hand, untabify deals with the whole file. It changes parts
> you have never edited or viewed.
>
> The setq-default part means that you're setting the default value for
> buffers. But modes in buffers may over-ride it with a local variable
> write. I'm not sure that you need setq-default here.
>
> BR,
> Robert Thorpe
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Indenting with spaces rather than tabs
2021-01-29 13:04 ` wael-zwaiter
@ 2021-01-29 13:10 ` moasenwood--- via Users list for the GNU Emacs text editor
2021-01-30 18:46 ` Robert Thorpe
1 sibling, 0 replies; 11+ messages in thread
From: moasenwood--- via Users list for the GNU Emacs text editor @ 2021-01-29 13:10 UTC (permalink / raw)
To: help-gnu-emacs
wael-zwaiter wrote:
> Can I do as follows, so that tabs are removed when
> "dfv-untabify-state" is "true" [...]
I don't see why not.
--
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Indenting with spaces rather than tabs
2021-01-29 13:04 ` wael-zwaiter
2021-01-29 13:10 ` moasenwood--- via Users list for the GNU Emacs text editor
@ 2021-01-30 18:46 ` Robert Thorpe
2021-01-30 19:25 ` wael-zwaiter
1 sibling, 1 reply; 11+ messages in thread
From: Robert Thorpe @ 2021-01-30 18:46 UTC (permalink / raw)
To: wael-zwaiter; +Cc: help-gnu-emacs
wael-zwaiter@gmx.com writes:
> Can I do as follows, so that tabs are removed when "dfv-untabify-state"
> is "true".
>
> (defvar dfv-untabify-state nil)
> (defun clean-before-save ()
> "Removes trailing spaces and tabs upon exiting"
>
> (delete-trailing-whitespace)
> (when (dfv-untabify-state)
> (unless (member major-mode '(makefile-gmake-mode makefile-mode))
> (untabify (point-min) (point-max))) ))
Yes you can do that. I think Mr.Berg gave some similar code in this
thread.
Be careful though about accidentally wrecking files. I notice you've
exempted makefiles, which is a good idea. You might want to exempt
more, like config files.
If you're doing work on a VC system with others then changing tabs
becomes a major irritation. That's because it creates a lot of false
changes (i.e. line changes where the code hasn't really changed).
BR,
Robert Thorpe
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Indenting with spaces rather than tabs
2021-01-30 18:46 ` Robert Thorpe
@ 2021-01-30 19:25 ` wael-zwaiter
2021-01-31 6:02 ` Robert Thorpe
0 siblings, 1 reply; 11+ messages in thread
From: wael-zwaiter @ 2021-01-30 19:25 UTC (permalink / raw)
To: Robert Thorpe; +Cc: help-gnu-emacs
I am having problems with this code
(defun break-comments ()
"Break lines when they exceed a specific character length."
(setq-local comment-auto-fill-only-comments t))
(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)
(auto-fill-mode)
(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)
;;
(setq dfv-break-comments-state 1)
(message "%s" "Break comments using prog-mode-hook")) ))
;; Break comments using auto-fill
(global-set-key (kbd "H-q") #'cycle-break-comments)
> Sent: Sunday, January 31, 2021 at 6:46 AM
> From: "Robert Thorpe" <rt@robertthorpeconsulting.com>
> To: wael-zwaiter@gmx.com
> Cc: help-gnu-emacs@gnu.org
> Subject: Re: Indenting with spaces rather than tabs
>
> wael-zwaiter@gmx.com writes:
>
> > Can I do as follows, so that tabs are removed when "dfv-untabify-state"
> > is "true".
> >
> > (defvar dfv-untabify-state nil)
> > (defun clean-before-save ()
> > "Removes trailing spaces and tabs upon exiting"
> >
> > (delete-trailing-whitespace)
> > (when (dfv-untabify-state)
> > (unless (member major-mode '(makefile-gmake-mode makefile-mode))
> > (untabify (point-min) (point-max))) ))
>
> Yes you can do that. I think Mr.Berg gave some similar code in this
> thread.
>
> Be careful though about accidentally wrecking files. I notice you've
> exempted makefiles, which is a good idea. You might want to exempt
> more, like config files.
>
> If you're doing work on a VC system with others then changing tabs
> becomes a major irritation. That's because it creates a lot of false
> changes (i.e. line changes where the code hasn't really changed).
>
> BR,
> Robert Thorpe
>
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Indenting with spaces rather than tabs
2021-01-30 19:25 ` wael-zwaiter
@ 2021-01-31 6:02 ` Robert Thorpe
2021-01-31 6:11 ` moasenwood--- via Users list for the GNU Emacs text editor
0 siblings, 1 reply; 11+ messages in thread
From: Robert Thorpe @ 2021-01-31 6:02 UTC (permalink / raw)
To: wael-zwaiter; +Cc: help-gnu-emacs
wael-zwaiter@gmx.com writes:
> I am having problems with this code
>
> (defun break-comments ()
> "Break lines when they exceed a specific character length."
> (setq-local comment-auto-fill-only-comments t))
>
> (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)
> (auto-fill-mode)
> (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)
> ;;
> (setq dfv-break-comments-state 1)
> (message "%s" "Break comments using prog-mode-hook")) ))
>
> ;; Break comments using auto-fill
> (global-set-key (kbd "H-q") #'cycle-break-comments)
I'm not sure what you're trying to do.
I don't see how your code can cycle things. You always add this hooks,
and you never take them away. Also, I think that pcase always runs the
case "_". I may be wrong, since I don't use it.
BR,
Robert Thorpe
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Indenting with spaces rather than tabs
2021-01-31 6:02 ` Robert Thorpe
@ 2021-01-31 6:11 ` moasenwood--- via Users list for the GNU Emacs text editor
0 siblings, 0 replies; 11+ messages in thread
From: moasenwood--- via Users list for the GNU Emacs text editor @ 2021-01-31 6:11 UTC (permalink / raw)
To: help-gnu-emacs
Robert Thorpe wrote:
> I'm not sure what you're trying to do.
No... me neither? :O
> Also, I think that pcase always runs the case "_". I may be
> wrong, since I don't use it.
(defvar some-var)
(setq some-var 12)
(pcase some-var
(12 (message "one two one two"))
(_ (message "not always run")) ) ; one two one two
(pcase some-var
(1 (message "oh, no!"))
(_ (message "but sometimes it is")) ) ; but sometimes it is
--
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Indenting with spaces rather than tabs
2021-01-29 2:00 ` moasenwood--- via Users list for the GNU Emacs text editor
@ 2021-02-01 9:46 ` Philip K.
2021-02-01 9:59 ` moasenwood--- via Users list for the GNU Emacs text editor
0 siblings, 1 reply; 11+ messages in thread
From: Philip K. @ 2021-02-01 9:46 UTC (permalink / raw)
To: help-gnu-emacs
moasenwood--- via Users list for the GNU Emacs text editor
<help-gnu-emacs@gnu.org> writes:
> wael-zwaiter wrote:
>
>> Want to indent with spaces rather than tabs and have found
>> the command
>>
>> (setq-default indent-tabs-mode nil)
>>
>> But one can also use "M-x untabify".
>>
>> What should I use for my init file?
>
> (defun untab-all ()
> (unless (member major-mode '(makefile-gmake-mode
> makefile-mode) ) ; exceptions
This should probably be (unless (derived-mode-p 'makefile-mode) ...)
> (untabify (point-min) (point-max)))
> nil) ; tell "did not write buffer to disk"
>
> (setq-default tab-width 3)
>
> (setq-default indent-tabs-mode nil)
>
> ;; (setq before-save-hook nil)
> (defun before-save-hook-f ()
> (untab-all)
> (delete-trailing-whitespace) )
> (add-hook 'before-save-hook #'before-save-hook-)f
--
Philip K.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Indenting with spaces rather than tabs
2021-02-01 9:46 ` Philip K.
@ 2021-02-01 9:59 ` moasenwood--- via Users list for the GNU Emacs text editor
0 siblings, 0 replies; 11+ messages in thread
From: moasenwood--- via Users list for the GNU Emacs text editor @ 2021-02-01 9:59 UTC (permalink / raw)
To: help-gnu-emacs
Philip K. wrote:
>> (defun untab-all ()
>> (unless (member major-mode '(makefile-gmake-mode
>> makefile-mode) ) ; exceptions
>
> This should probably be (unless (derived-mode-p
> 'makefile-mode) ...)
There are other exceptions as well (not entered, but that
aren't Makefiles), but OK, I can have that, i.e.
your suggestion, and other exceptions as well ... TODO list
--
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2021-02-01 9:59 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-01-29 1:26 Indenting with spaces rather than tabs wael-zwaiter
2021-01-29 2:00 ` moasenwood--- via Users list for the GNU Emacs text editor
2021-02-01 9:46 ` Philip K.
2021-02-01 9:59 ` moasenwood--- via Users list for the GNU Emacs text editor
2021-01-29 5:25 ` Robert Thorpe
2021-01-29 13:04 ` wael-zwaiter
2021-01-29 13:10 ` moasenwood--- via Users list for the GNU Emacs text editor
2021-01-30 18:46 ` Robert Thorpe
2021-01-30 19:25 ` wael-zwaiter
2021-01-31 6:02 ` Robert Thorpe
2021-01-31 6:11 ` moasenwood--- via Users list for the GNU Emacs text editor
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).