unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Ergus <spacibba@aol.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: acm@muc.de, emacs-devel@gnu.org
Subject: Re: Supporting tabs for indentation, spaces for alignment
Date: Thu, 11 Apr 2019 16:43:42 +0200	[thread overview]
Message-ID: <20190411144342.ozqqehwpoamvaanu@Ergus> (raw)
In-Reply-To: <83bm1c656x.fsf@gnu.org>

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.




  reply	other threads:[~2019-04-11 14:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190411144342.ozqqehwpoamvaanu@Ergus \
    --to=spacibba@aol.com \
    --cc=acm@muc.de \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).