* Re: Supporting tabs for indentation, spaces for alignment
@ 2019-04-11 9:02 Alan Mackenzie
2019-04-11 10:24 ` Ergus
0 siblings, 1 reply; 8+ messages in thread
From: Alan Mackenzie @ 2019-04-11 9:02 UTC (permalink / raw)
To: Ergus; +Cc: emacs-devel
Hello again, Ergus.
You were asking in your post Subject: Re: C style alist question? for a
way of indenting CC Mode modes with "tabs for indentation and spaces for
alignment."
The topic has come up before, and I answered back in 2008 with the
following post to the OP and bug-cc-mode@gnu.org. It's a bit wordy, I
admit, but does provide a way of getting what you're asking for. I
admit not having tried it out recently.
--
Alan Mackenzie (Nuremberg, Germany).
----- Forwarded message from Alan Mackenzie <acm@muc.de> -----
X-Spam-Checker-Version: SpamAssassin 3.2.0 (2007-05-01) on colin2.muc.de
X-Spam-Level:
X-Spam-Status: No, score=0.1 required=5.0 tests=AWL,BAYES_50 autolearn=no version=3.2.0
Date: Fri, 11 Apr 2008 20:31:42 +0000
To: Mike Sullivan <msully4321@gmail.com>
Subject: Re: Supporting tabs for indentation, spaces for alignment
X-Delivery-Agent: TMDA/1.1.5 (Fettercairn)
From: Alan Mackenzie <acm@muc.de>
X-Primary-Address: acm@muc.de
X-detected-kernel: by monty-python.gnu.org: FreeBSD 4.6-4.9
Cc: bug-cc-mode@gnu.org
X-BeenThere: cc-mode-help@lists.sourceforge.net
X-Mailman-Version: 2.1.8
Reply-To: bug-cc-mode@gnu.org
List-Id: "Bug reports, feature requests, and general talk about CC Mode." <cc-mode-help.lists.sourceforge.net>
List-Unsubscribe: <https://lists.sourceforge.net/lists/listinfo/cc-mode-help>, <mailto:cc-mode-help-request@lists.sourceforge.net?subject=unsubscribe>
List-Archive: <http://sourceforge.net/mailarchive/forum.php?forum_name=cc-mode-help>
List-Post: <mailto:cc-mode-help@lists.sourceforge.net>
List-Help: <mailto:cc-mode-help-request@lists.sourceforge.net?subject=help>
List-Subscribe: <https://lists.sourceforge.net/lists/listinfo/cc-mode-help>, <mailto:cc-mode-help-request@lists.sourceforge.net?subject=subscribe>
Hi, Mike,
Sorry it's taken me so long to answer.
On Wed, Jan 09, 2008 at 02:04:40AM -0600, Mike Sullivan wrote:
> Currently, cc-mode offers no simple way to use tabs for indentation,
> but spaces for alignment (as described many places on the web,
> including http://wiki.chad.org/wiki?IndentationUsingTabs). Is there
> any chance that this will be added as a feature in a future version?
OK: Here's what I think that page means. Supposing your tab-width is 8,
in
{
if (a really long conditional that won't fit
onto one line) { ....
....
}
}
, you want (I think), tabs here:
tttttttt
, yet spaces here:
....
If your tab-width were 2, you'd want to see this:
{
if (a really long conditional that won't fit
onto one line) { ....
....
}
}
, with tabs here:
tt
, and spaces here:
....
.
Currently, assuming indent-tabs-mode is set, with a sufficiently large
tab-width (say, 8), this is what you'll get, but with a smaller
tab-width (2), the four spaces will be replaced by two tabs, not what
you want.
No, there are no plans for putting such a feature into CC Mode at the
moment. One could opine that the opinions on that web page are somewhat
opinionated, capable of triggering religious wars. ;-) My own view is
that that indentation strategy would be a right royal pain, unless it
somehow got enforced 100% by the project's management and _every_ editor
in use supported it. To implement the idea "properly" in CC Mode would
entail a non-trivial amount of work.
However, this is the sort of thing that seems tailor-made for
c-special-indent-hook (see page "Other Indentation" in the CC Mode
manual), and shows just how flexible Emacs (in general) and CC Mode (in
particular) are, and just how superior they are to lesser editors. ;-)
I've written a quick hack, to give you an idea how this sort of thing
could work. Here's the source file I tried it on, _without_ tabs here
(it goes more easily into an email that way), with c-basic-offset = 3:
int foo (char a, char b, char c, char d, char e,
char f, char g) {
if (a = 'a'
&& b = 'b'
&& c = 'c')
{
print "hi!\n" ;
return 0 ;
}
return 1 ;
}
As a quick tip, to _see_ tabs in a buffer, do M-x hi-lock-mode, then C-x
w h. On being prompted for a regexp just do C-q <tab> <CR>, then select
some highlighting face.
OK, here's the hack:
(defun ms-space-for-alignment ()
"Make the current line use tabs for indentation and spaces for alignment.
It is intended to be called from the hook
`c-special-indent-hook'. It assumes that `indent-tabs-mode' is
non-nil and probably assumes that `c-basic-offset' is the same as
`tab-width'."
(save-excursion
(let* ((indent-pos (progn (back-to-indentation) (point)))
(indent-col (current-column))
(syn-elt (car c-syntactic-context))
(syn-sym (c-langelem-sym syn-elt)))
(when (memq syn-sym '(arglist-cont-nonempty)) ;; <==============
(let* ((syn-anchor (c-langelem-pos syn-elt))
(anchor-col (progn (goto-char syn-anchor)
(back-to-indentation)
(current-column)))
num-tabs)
;;
(goto-char indent-pos)
(delete-horizontal-space)
(insert-char ?\t (/ anchor-col tab-width))
(insert-char ?\ (- indent-col (current-column))))))))
To enable it, do this:
M-: (setq indent-tabs-mode t)
M-: (setq tab-width 3)
M-: (setq c-basic-offset tab-width)
(add-hook 'c-special-indent-hook 'ms-space-for-alignment nil t)
If you were to develop this hack into fully working code, I would be
willing to put it into the next full version of CC Mode (subject to the
customary copyright assignment to the FSF, which we all have to do).
> Thanks, Mike Sullivan
Happy hacking!
--
Alan Mackenzie (Nuremberg, Germany).
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
----- End forwarded message -----
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Supporting tabs for indentation, spaces for alignment
2019-04-11 9:02 Supporting tabs for indentation, spaces for alignment Alan Mackenzie
@ 2019-04-11 10:24 ` Ergus
2019-04-11 13:29 ` Eli Zaretskii
2019-04-12 15:54 ` Alan Mackenzie
0 siblings, 2 replies; 8+ messages in thread
From: Ergus @ 2019-04-11 10:24 UTC (permalink / raw)
To: Alan Mackenzie; +Cc: emacs-devel
Hi Alan:
Very thanks for replying. I will try to implement your solution for now
in my config.
But I'm wondering if after 11 years, with much better machines, improved
emacs with many new functionalities (most of them nothing to do with a
text editor) and the constant growing of languages that uses cc-mode as
a base (rust || C++>=11 for example).
But also with new indentation styles (like the google's one which is
by far the most popular package in melpa).
And this package which seems to work; so some experience already:
https://github.com/jcsalomon/smarttabs
And the increase in popularity of other editors/ides which use different
policies (from vim, kdevelop, eclipse, notepad++, visual-studio-code);
so a emacs user (like me) needs to attach and don't break the global
project schema. Maybe it makes sense to think how to add other
tab-indent-policies and styles in the c-indent-alist list. Even if they
are not the defaults.
So the users could find their needs without writing 40 lisp lines and
read 20 manual pages full of therms that makes sense only after reading
1000 previous pages. Or needing to install an external package that
potentially gets abandon.
On Thu, Apr 11, 2019 at 09:02:23AM +0000, Alan Mackenzie wrote:
>Hello again, Ergus.
>
>You were asking in your post Subject: Re: C style alist question? for a
>way of indenting CC Mode modes with "tabs for indentation and spaces for
>alignment."
>
>The topic has come up before, and I answered back in 2008 with the
>following post to the OP and bug-cc-mode@gnu.org. It's a bit wordy, I
>admit, but does provide a way of getting what you're asking for. I
>admit not having tried it out recently.
>
>--
>Alan Mackenzie (Nuremberg, Germany).
>
>
>----- Forwarded message from Alan Mackenzie <acm@muc.de> -----
>
>X-Spam-Checker-Version: SpamAssassin 3.2.0 (2007-05-01) on colin2.muc.de
>X-Spam-Level:
>X-Spam-Status: No, score=0.1 required=5.0 tests=AWL,BAYES_50 autolearn=no version=3.2.0
>Date: Fri, 11 Apr 2008 20:31:42 +0000
>To: Mike Sullivan <msully4321@gmail.com>
>Subject: Re: Supporting tabs for indentation, spaces for alignment
>X-Delivery-Agent: TMDA/1.1.5 (Fettercairn)
>From: Alan Mackenzie <acm@muc.de>
>X-Primary-Address: acm@muc.de
>X-detected-kernel: by monty-python.gnu.org: FreeBSD 4.6-4.9
>Cc: bug-cc-mode@gnu.org
>X-BeenThere: cc-mode-help@lists.sourceforge.net
>X-Mailman-Version: 2.1.8
>Reply-To: bug-cc-mode@gnu.org
>List-Id: "Bug reports, feature requests, and general talk about CC Mode." <cc-mode-help.lists.sourceforge.net>
>List-Unsubscribe: <https://lists.sourceforge.net/lists/listinfo/cc-mode-help>, <mailto:cc-mode-help-request@lists.sourceforge.net?subject=unsubscribe>
>List-Archive: <http://sourceforge.net/mailarchive/forum.php?forum_name=cc-mode-help>
>List-Post: <mailto:cc-mode-help@lists.sourceforge.net>
>List-Help: <mailto:cc-mode-help-request@lists.sourceforge.net?subject=help>
>List-Subscribe: <https://lists.sourceforge.net/lists/listinfo/cc-mode-help>, <mailto:cc-mode-help-request@lists.sourceforge.net?subject=subscribe>
>
>Hi, Mike,
>
>Sorry it's taken me so long to answer.
>
>On Wed, Jan 09, 2008 at 02:04:40AM -0600, Mike Sullivan wrote:
>> Currently, cc-mode offers no simple way to use tabs for indentation,
>> but spaces for alignment (as described many places on the web,
>> including http://wiki.chad.org/wiki?IndentationUsingTabs). Is there
>> any chance that this will be added as a feature in a future version?
>
>OK: Here's what I think that page means. Supposing your tab-width is 8,
>in
>
>{
> if (a really long conditional that won't fit
> onto one line) { ....
> ....
> }
>}
>
>, you want (I think), tabs here:
>tttttttt
>, yet spaces here:
> ....
>
>If your tab-width were 2, you'd want to see this:
>
>{
> if (a really long conditional that won't fit
> onto one line) { ....
> ....
> }
>}
>
>, with tabs here:
>tt
>, and spaces here:
> ....
>
>.
>
>Currently, assuming indent-tabs-mode is set, with a sufficiently large
>tab-width (say, 8), this is what you'll get, but with a smaller
>tab-width (2), the four spaces will be replaced by two tabs, not what
>you want.
>
>No, there are no plans for putting such a feature into CC Mode at the
>moment. One could opine that the opinions on that web page are somewhat
>opinionated, capable of triggering religious wars. ;-) My own view is
>that that indentation strategy would be a right royal pain, unless it
>somehow got enforced 100% by the project's management and _every_ editor
>in use supported it. To implement the idea "properly" in CC Mode would
>entail a non-trivial amount of work.
>
>However, this is the sort of thing that seems tailor-made for
>c-special-indent-hook (see page "Other Indentation" in the CC Mode
>manual), and shows just how flexible Emacs (in general) and CC Mode (in
>particular) are, and just how superior they are to lesser editors. ;-)
>
>I've written a quick hack, to give you an idea how this sort of thing
>could work. Here's the source file I tried it on, _without_ tabs here
>(it goes more easily into an email that way), with c-basic-offset = 3:
>
>
>int foo (char a, char b, char c, char d, char e,
> char f, char g) {
> if (a = 'a'
> && b = 'b'
> && c = 'c')
> {
> print "hi!\n" ;
> return 0 ;
> }
> return 1 ;
>}
>
>
>As a quick tip, to _see_ tabs in a buffer, do M-x hi-lock-mode, then C-x
>w h. On being prompted for a regexp just do C-q <tab> <CR>, then select
>some highlighting face.
>
>OK, here's the hack:
>
>(defun ms-space-for-alignment ()
> "Make the current line use tabs for indentation and spaces for alignment.
>
>It is intended to be called from the hook
>`c-special-indent-hook'. It assumes that `indent-tabs-mode' is
>non-nil and probably assumes that `c-basic-offset' is the same as
>`tab-width'."
> (save-excursion
> (let* ((indent-pos (progn (back-to-indentation) (point)))
> (indent-col (current-column))
> (syn-elt (car c-syntactic-context))
> (syn-sym (c-langelem-sym syn-elt)))
> (when (memq syn-sym '(arglist-cont-nonempty)) ;; <==============
> (let* ((syn-anchor (c-langelem-pos syn-elt))
> (anchor-col (progn (goto-char syn-anchor)
> (back-to-indentation)
> (current-column)))
> num-tabs)
> ;;
> (goto-char indent-pos)
> (delete-horizontal-space)
> (insert-char ?\t (/ anchor-col tab-width))
> (insert-char ?\ (- indent-col (current-column))))))))
>
>To enable it, do this:
>
> M-: (setq indent-tabs-mode t)
> M-: (setq tab-width 3)
> M-: (setq c-basic-offset tab-width)
> (add-hook 'c-special-indent-hook 'ms-space-for-alignment nil t)
>
>
>If you were to develop this hack into fully working code, I would be
>willing to put it into the next full version of CC Mode (subject to the
>customary copyright assignment to the FSF, which we all have to do).
>
>
>> Thanks, Mike Sullivan
>
>Happy hacking!
>
>--
>Alan Mackenzie (Nuremberg, Germany).
>
>-------------------------------------------------------------------------
>This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
>Don't miss this year's exciting event. There's still time to save $100.
>Use priority code J8TL2D2.
>http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
>
>----- End forwarded message -----
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Supporting tabs for indentation, spaces for alignment
2019-04-11 10:24 ` Ergus
@ 2019-04-11 13:29 ` Eli Zaretskii
2019-04-11 14:43 ` Ergus
2019-04-12 15:54 ` Alan Mackenzie
1 sibling, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2019-04-11 13:29 UTC (permalink / raw)
To: Ergus; +Cc: acm, emacs-devel
> Date: Thu, 11 Apr 2019 12:24:05 +0200
> From: Ergus <spacibba@aol.com>
> Cc: emacs-devel@gnu.org
>
> So the users could find their needs without writing 40 lisp lines and
> read 20 manual pages full of therms that makes sense only after reading
> 1000 previous pages.
I don't think you need to write any Lisp for that: CC Mode includes a
feature called "Interactive Customization of Indentation", read all
about it in the CC Mode manual.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Supporting tabs for indentation, spaces for alignment
2019-04-11 13:29 ` Eli Zaretskii
@ 2019-04-11 14:43 ` Ergus
0 siblings, 0 replies; 8+ messages in thread
From: Ergus @ 2019-04-11 14:43 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: acm, emacs-devel
On Thu, Apr 11, 2019 at 04:29:26PM +0300, Eli Zaretskii wrote:
>> Date: Thu, 11 Apr 2019 12:24:05 +0200
>> From: Ergus <spacibba@aol.com>
>> Cc: emacs-devel@gnu.org
>>
>> So the users could find their needs without writing 40 lisp lines and
>> read 20 manual pages full of therms that makes sense only after reading
>> 1000 previous pages.
>
>I don't think you need to write any Lisp for that: CC Mode includes a
>feature called "Interactive Customization of Indentation", read all
>about it in the CC Mode manual.
Hi Eli:
I have already seen that part in the manual. But these options I'm
talking about are not available with simple customization.
The google's indentation style can be included in the list of styles (at
least the basic support) because there are many details and offsets to
correct. And really many people seems to be using it (look at the melpa
statistics).
But also the tab-width and indent-tabs-mode normally are set in the init
file (is what we see in the documentation, and in emacswiki), but if the
user needs to change style, the init values will "win" so he ends with a
mixed style not very useful.
The way to avoid that (the right way) is to create a style that inherits
from one of the existing like I do for linux style:
```
(c-add-style "mylinux"
'("linux"
(tab-width . 4)
(c-basic-offset . 4)
(fill-column . 80)
(c-offsets-alist (inline-open . 0)
(cpp-macro . 0)
)))
(setq-default c-default-style
'((java-mode . "java")
(awk-mode . "awk")
(other . "mylinux")))
```
But this for a new user this code is pretty close to Latin or ancient
Cyrillic.
Using the guess command in cc-mode at least for me didn't give good
results because not all the syntactic symbols were present in a single
file. So finally I ended doing most if it manually.
Finally the indent with tabs align with spaces behavior, as it is not a
customizable behavior; it needs to be implemented with the Alan's
recommended work around (which is not in the documentation):
```
(defun ms-space-for-alignment ()
"Make the current line use tabs for indentation and spaces for alignment.
It is intended to be called from the hook
`c-special-indent-hook'. It assumes that `indent-tabs-mode' is
non-nil and probably assumes that `c-basic-offset' is the same as
`tab-width'."
(save-excursion
(let* ((indent-pos (progn (back-to-indentation) (point)))
(indent-col (current-column))
(syn-elt (car c-syntactic-context))
(syn-sym (c-langelem-sym syn-elt)))
(when (memq syn-sym '(arglist-cont-nonempty)) ;; <==============
(let* ((syn-anchor (c-langelem-pos syn-elt))
(anchor-col (progn (goto-char syn-anchor)
(back-to-indentation)
(current-column)))
num-tabs)
;;
(goto-char indent-pos)
(delete-horizontal-space)
(insert-char ?\t (/ anchor-col tab-width))
(insert-char ?\ (- indent-col (current-column))))))))
```
To enable it, do this:
```
M-: (setq indent-tabs-mode t)
M-: (setq tab-width 3)
M-: (setq c-basic-offset tab-width)
(add-hook 'c-special-indent-hook 'ms-space-for-alignment nil t)
```
Or use the package... But this will need more code in case the user
changes the style to a not tab-indented one.
What I mean is that such small pieces of code are very useful for many
people and can save time and customization time/code from the user (and
potential error sources) if they are added as customization options.
But also those small details represent a big difference for the final user's
experience (specially for new ones)
Sorry for bothering with this because they are basic editor
functionalities people expect to have without too much effort in an
editor. We can play tetris, music and there is a psychoanalyst, a pdf
player debugger interface and so on... but it needs an external package
and coding for so a basic editor tasks...
It is like we put a lot of effort extending emacs, but not the editor/ide
features. Which is where it is expected to shine first and more.
Sorry for the long mail.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Supporting tabs for indentation, spaces for alignment
2019-04-11 10:24 ` Ergus
2019-04-11 13:29 ` Eli Zaretskii
@ 2019-04-12 15:54 ` Alan Mackenzie
2019-04-12 17:00 ` Ergus
[not found] ` <b483d42ddde945b3a479800566aa257c@lanl.gov>
1 sibling, 2 replies; 8+ messages in thread
From: Alan Mackenzie @ 2019-04-12 15:54 UTC (permalink / raw)
To: Ergus; +Cc: emacs-devel
Hello, Ergus.
On Thu, Apr 11, 2019 at 12:24:05 +0200, Ergus wrote:
> Hi Alan:
> Very thanks for replying. I will try to implement your solution for now
> in my config.
> But I'm wondering if after 11 years, with much better machines, improved
> emacs with many new functionalities (most of them nothing to do with a
> text editor) and the constant growing of languages that uses cc-mode as
> a base (rust || C++>=11 for example).
> But also with new indentation styles (like the google's one which is
> by far the most popular package in melpa).
> And this package which seems to work; so some experience already:
> https://github.com/jcsalomon/smarttabs
> And the increase in popularity of other editors/ides which use different
> policies (from vim, kdevelop, eclipse, notepad++, visual-studio-code);
> so a emacs user (like me) needs to attach and don't break the global
> project schema. Maybe it makes sense to think how to add other
> tab-indent-policies and styles in the c-indent-alist list. Even if they
> are not the defaults.
All of what you have just written is far more vague and abstract than
your previous posts.
Getting concrete again, my understanding (please correct me if I am
wrong) of what you are suggesting is: "continuation" CC Mode source
lines should be indented with tabs up to the indent position of the
"main" line, and spaces after that. For some value of "continuation"
and "main" (see below).
This might not be all that difficult to implement. First the
"continuation" CC Mode syntactic symbols (e.g. arglist-cont-nonempty)
will need to be firmly identified, and a list made of them, say
c-continuation-syntactic-symbols.
Then the writer of the CC Mode style will need to set a flag (which
might be called c-limit-indentation-tabs or something like that) to
non-nil in the style. Also she will need to set indent-tabs-mode to
non-nil.
At run time, if the main symbol in the syntactic context is a member of
c-continuation-syntactic-symbols, the column number of its anchor
position will be determined. The CC Mode indenting function will not
permit the initial sequence of tabs to extend beyond this anchor
position, replacing such tabs with spaces beyond that point.
> So the users could find their needs without writing 40 lisp lines and
> read 20 manual pages full of therms that makes sense only after reading
> 1000 previous pages. Or needing to install an external package that
> potentially gets abandon.
I think you're exaggerating just a little bit; it was only 27 lines of
Lisp. ;-) But I take the point. That workaround was only really
suitable for a Lisp hacker.
Have you any views on my above proposed strategy?
--
Alan Mackenzie (Nuremberg, Germany).
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Supporting tabs for indentation, spaces for alignment
2019-04-12 15:54 ` Alan Mackenzie
@ 2019-04-12 17:00 ` Ergus
[not found] ` <b483d42ddde945b3a479800566aa257c@lanl.gov>
1 sibling, 0 replies; 8+ messages in thread
From: Ergus @ 2019-04-12 17:00 UTC (permalink / raw)
To: Alan Mackenzie; +Cc: emacs-devel
On Fri, Apr 12, 2019 at 03:54:42PM +0000, Alan Mackenzie wrote:
Hi again:
>Hello, Ergus.
>
>On Thu, Apr 11, 2019 at 12:24:05 +0200, Ergus wrote:
>
>All of what you have just written is far more vague and abstract than
>your previous posts.
>
>Getting concrete again, my understanding (please correct me if I am
>wrong) of what you are suggesting is: "continuation" CC Mode source
>lines should be indented with tabs up to the indent position of the
>"main" line, and spaces after that. For some value of "continuation"
>and "main" (see below).
>
Yes, I have seen only 3 alternatives so far (in my short experience)
which are:
1) The actual emacs default.
2) Add an extra tab to continuation lines and no align with spaces at
all (some projects don't like to mix tabs with spaces, so they prefer
to ignore align)
3) Indent-with-tabs align with spaces.
>This might not be all that difficult to implement. First the
>"continuation" CC Mode syntactic symbols (e.g. arglist-cont-nonempty)
>will need to be firmly identified, and a list made of them, say
>c-continuation-syntactic-symbols.
>
Ok, there are not too many right? For C++ I only remember
arglist-cont-nonempty, stream-op and template-args-cont.
>Then the writer of the CC Mode style will need to set a flag (which
>might be called c-limit-indentation-tabs or something like that) to
>non-nil in the style. Also she will need to set indent-tabs-mode to
>non-nil.
>
Could we just add special values to indent-tabs-mode? So t is the
default (like now) and "limit-indentation-tabs" (or similar) will be
this policy? So for other possible future policies we just need to add
other values right? As it is buffer local should not affect other
modes.
>At run time, if the main symbol in the syntactic context is a member of
>c-continuation-syntactic-symbols, the column number of its anchor
>position will be determined.
This is what is not clear to me how to do it right. For example in case
of using templates.
>The CC Mode indenting function will not
>permit the initial sequence of tabs to extend beyond this anchor
>position, replacing such tabs with spaces beyond that point.
>
>> So the users could find their needs without writing 40 lisp lines and
>> read 20 manual pages full of therms that makes sense only after reading
>> 1000 previous pages. Or needing to install an external package that
>> potentially gets abandon.
>
>I think you're exaggerating just a little bit; it was only 27 lines of
>Lisp. ;-) But I take the point. That workaround was only really
>suitable for a Lisp hacker.
>
Yes, maybe a little bit, I am from Latin America so it is normal for
us. We also use to write long emails and talk a lot :P
>Have you any views on my above proposed strategy?
>
If you give me the hints where in the code to implement the changes (As
Eli did for display-fill-column), maybe I can start with a draft
version. It will take a while because am not very lispy :(. But I think
these small features are very important and make the difference.
>--
>Alan Mackenzie (Nuremberg, Germany).
Very thanks for replying.
Ergus.
^ permalink raw reply [flat|nested] 8+ messages in thread
[parent not found: <b483d42ddde945b3a479800566aa257c@lanl.gov>]
* Re: Supporting tabs for indentation, spaces for alignment
[not found] ` <b483d42ddde945b3a479800566aa257c@lanl.gov>
@ 2019-04-13 13:54 ` Alan Mackenzie
2019-04-13 15:56 ` Ergus
0 siblings, 1 reply; 8+ messages in thread
From: Alan Mackenzie @ 2019-04-13 13:54 UTC (permalink / raw)
To: Herring, Davis; +Cc: emacs-devel
Hello, Davis.
On Fri, Apr 12, 2019 at 16:39:16 +0000, Herring, Davis wrote:
> [Sent off-list because I don't know whether my DMARC issues have been
> addressed. Feel free to share it there if you'd like to make a public
> reply.]
I'm doing this. I believe these mail issues, as they interact with
mailing lists, are a Hard Problem. I'm not sure how much progress has
been made on this by the admins, but they certainly haven't been
disregarding the problem.
> > Getting concrete again, my understanding (please correct me if I am
> > wrong) of what you are suggesting is: "continuation" CC Mode source
> > lines should be indented with tabs up to the indent position of the
> > "main" line, and spaces after that. For some value of
> > "continuation" and "main" (see below).
> I'm not saying your description in terms of CC Mode internals was
> incorrect, but I'd like to provide an implementation-independent
> description that can be easily verified. (Also, in case it hasn't
> been posted recently, the Emacs Wiki discusses this idea in some depth
> <https://www.emacswiki.org/emacs/SmartTabs>.)
Thanks, I've read that. I've also downloaded the pertinent Elisp file.
I'm not quite sure how smart-tabs-mode works, yet, so I'm also not sure
what a secific CC Mode implementation could add.
> The definition of "continuation" is simply that tabs are used whenever
> the user chooses the width of indentation and spaces are used whenever
> the editor chooses it (by comparing column positions in the text).
So, roughly speaking, if a CC Mode "offset" is + or ++, then tabs would
be appropriate, otherwise spaces.
> There is a tacit assumption here that the amounts of indentation
> chosen by the user are expressed in units of tabs. Conveniently, CC
> Mode already defines indentation in terms of levels, so this just
> means that a level equals a tab--i.e., that c-basic-offset and
> tab-width are not independent. It probably makes sense to, when this
> style is engaged, (setq tab-width c-basic-offset) after computing the
> latter from whatever other style information since it is more specific
> than any global setting of tab-width.
Yes. I'll work out the precise details.
But I'm now wondering why I should want to write a CC Mode specific
implementation.
> Hope this helps,
Very much so, thanks!
> Davis
--
Alan Mackenzie (Nuremberg, Germany).
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Supporting tabs for indentation, spaces for alignment
2019-04-13 13:54 ` Alan Mackenzie
@ 2019-04-13 15:56 ` Ergus
0 siblings, 0 replies; 8+ messages in thread
From: Ergus @ 2019-04-13 15:56 UTC (permalink / raw)
To: Alan Mackenzie; +Cc: emacs-devel
On Sat, Apr 13, 2019 at 01:54:46PM +0000, Alan Mackenzie wrote:
>Hello, Davis.
>
>On Fri, Apr 12, 2019 at 16:39:16 +0000, Herring, Davis wrote:
>> [Sent off-list because I don't know whether my DMARC issues have been
>> addressed. Feel free to share it there if you'd like to make a public
>> reply.]
>
>I'm doing this. I believe these mail issues, as they interact with
>mailing lists, are a Hard Problem. I'm not sure how much progress has
>been made on this by the admins, but they certainly haven't been
>disregarding the problem.
>
>> > Getting concrete again, my understanding (please correct me if I am
>> > wrong) of what you are suggesting is: "continuation" CC Mode source
>> > lines should be indented with tabs up to the indent position of the
>> > "main" line, and spaces after that. For some value of
>> > "continuation" and "main" (see below).
>
>> I'm not saying your description in terms of CC Mode internals was
>> incorrect, but I'd like to provide an implementation-independent
>> description that can be easily verified. (Also, in case it hasn't
>> been posted recently, the Emacs Wiki discusses this idea in some depth
>> <https://www.emacswiki.org/emacs/SmartTabs>.)
>
>Thanks, I've read that. I've also downloaded the pertinent Elisp file.
>I'm not quite sure how smart-tabs-mode works, yet, so I'm also not sure
>what a secific CC Mode implementation could add.
>
>> The definition of "continuation" is simply that tabs are used whenever
>> the user chooses the width of indentation and spaces are used whenever
>> the editor chooses it (by comparing column positions in the text).
>
>So, roughly speaking, if a CC Mode "offset" is + or ++, then tabs would
>be appropriate, otherwise spaces.
>
>> There is a tacit assumption here that the amounts of indentation
>> chosen by the user are expressed in units of tabs. Conveniently, CC
>> Mode already defines indentation in terms of levels, so this just
>> means that a level equals a tab--i.e., that c-basic-offset and
>> tab-width are not independent. It probably makes sense to, when this
>> style is engaged, (setq tab-width c-basic-offset) after computing the
>> latter from whatever other style information since it is more specific
>> than any global setting of tab-width.
>
>Yes. I'll work out the precise details.
>
>But I'm now wondering why I should want to write a CC Mode specific
>implementation.
>
>> Hope this helps,
>
>Very much so, thanks!
>
>> Davis
>
>--
>Alan Mackenzie (Nuremberg, Germany).
>
I agree that a general implementation could be a better approach,
because other modes could take advantage of it. At least the basic
infrastructure. But also because different modes will need to support
different customizable variants of this in the future and every mode
shouldn't reinvent the well ever time.
Nevertheless CC-mode will require a specific implementation any way
because there is more complexity with syntax analysis, but also because
most of the programming languages that exposes this issue needs cc-mode
in emacs.
Maybe we should first agree about what is the basic functionality that
needs to be added in the emacs core and then we could consider
specializations for cc-mode if they are needed (pretty sure they'll do).
I don't know if the other modes in emacs are implemented like cc-mode,
but the approach you mentioned yesterday is something that maybe fits
for most of them. So a basic infraestructure for the "continuation array"
may be language/mode independent.
Languages like python or julia where mixing tabs with spaced is
dangerous; probably need to assert to use only spaces or tabs (pep 8
recommends spaces only and it is kind of standard now... similar happens
in Fortran, most compilers support to use tabs, but not all). Pascal on
the other hand uses tabs, but the tab-width is usually 3 or 4. So, at
the end, every prog-mode will need a sort of specialization.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2019-04-13 15:56 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-04-11 9:02 Supporting tabs for indentation, spaces for alignment Alan Mackenzie
2019-04-11 10:24 ` Ergus
2019-04-11 13:29 ` Eli Zaretskii
2019-04-11 14:43 ` Ergus
2019-04-12 15:54 ` Alan Mackenzie
2019-04-12 17:00 ` Ergus
[not found] ` <b483d42ddde945b3a479800566aa257c@lanl.gov>
2019-04-13 13:54 ` Alan Mackenzie
2019-04-13 15:56 ` Ergus
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
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).