emacs-devel
[Top][All Lists]
Advanced

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

Re: Supporting tabs for indentation, spaces for alignment


From: Ergus
Subject: Re: Supporting tabs for indentation, spaces for alignment
Date: Thu, 11 Apr 2019 16:43:42 +0200
User-agent: NeoMutt/20180716

On Thu, Apr 11, 2019 at 04:29:26PM +0300, Eli Zaretskii wrote:
Date: Thu, 11 Apr 2019 12:24:05 +0200
From: Ergus <address@hidden>
Cc: address@hidden

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 via email to

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