# Customizing tab behavior for "%" comment in prolog-mode (emacs)

**URL:** https://swi-prolog.discourse.group/t/customizing-tab-behavior-for-comment-in-prolog-mode-emacs/1927
**Category:** Tools
**Created:** [February 27, 2020, 4:39pm UTC](https://swi-prolog.discourse.group/t/customizing-tab-behavior-for-comment-in-prolog-mode-emacs/1927 "2020-02-27T16:39:36Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)
#### Post date: [February 27, 2020, 4:39pm UTC](https://swi-prolog.discourse.group/t/customizing-tab-behavior-for-comment-in-prolog-mode-emacs/1927/1 "2020-02-27T16:39:36Z")

</div>

I’m using [Stefan Bruda’s Prolog mode for emacs](https://bruda.ca/emacs/prolog_mode_for_emacs) but I find the behavior with tab and “%” to be annoying … it always indents comments to column 32 (variable `comment-column`), even for lines starting with “%!”.

How can I change this behaviour? If I set `comment-column` to 0, then single-line comments get indented incorrectly:

```prolog
foo :-
% this is a comment
    bar.

```

instead of

```prolog
foo :-
    % this is a comment
    bar.

```

and if I leave `comment-column` at 32, then I get the following, which I don’t want:

```prolog
                              %! foo is det.
foo :-
                              % this is a comment
    bar.

```

---

<div class="post-metadata">

### Author: ![jamesnvc](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jamesnvc/32/14_2.png) [@jamesnvc](https://swi-prolog.discourse.group/u/jamesnvc)
#### Post date: [February 28, 2020, 1:24am UTC](https://swi-prolog.discourse.group/t/customizing-tab-behavior-for-comment-in-prolog-mode-emacs/1927/3 "2020-02-28T01:24:52Z")

</div>

I think I’ve linked this to you before, but I’m using a [slightly-modified version of the prolog.el](https://github.com/jamesnvc/dotfiles/blob/9e13ea5a176fbc2989640362b6bbb0c1d7511dcb/emacs.d/modules/prolog.el) that I think comes with Emacs that doesn’t seem to have this issue with indenting (I originally started working on this to fix the indentation of terms with dictionaries & character things like `0'.`).

> [@EricGT](#):
>
> we should have a new category for the tools

Probably a good idea…

---

<div class="post-metadata">

### Author: ![chansey97](https://avatars.discourse-cdn.com/v4/letter/c/e480ec/32.png) [@chansey97](https://swi-prolog.discourse.group/u/chansey97)
#### Post date: [December 11, 2021, 9:31am UTC](https://swi-prolog.discourse.group/t/customizing-tab-behavior-for-comment-in-prolog-mode-emacs/1927/4 "2021-12-11T09:31:29Z")

</div>

I met the same problem recently, but it seems to have been fixed by:

```prolog
(setq prolog-align-small-comments-flag nil)

```

Then the single-line comments get indented:

```prolog
foo :-
  % this is a comment
  bar.

```

> One new customizable variable has been added in version 1.28:
> 
> **prolog-align-small-comments-flag** (group “Prolog Indentation”) specifies how to handle “small” comments (the ones that start with a simgle “%”) as follows: When this variable is non-nil (default) small comments are aligned to `comment-column' (default 32) in all circumstances. When the variable is set to nil however small comments that begin a line (blank characters notwithstanding) will be treated just like “large” comments (the ones that start with “%%”). Note that small comments that start somewhere other than at the beginning of the line are still aligned to `comment-column’.

---

<div class="post-metadata">

### Author: ![chansey97](https://avatars.discourse-cdn.com/v4/letter/c/e480ec/32.png) [@chansey97](https://swi-prolog.discourse.group/u/chansey97)
#### Post date: [December 11, 2021, 10:17am UTC](https://swi-prolog.discourse.group/t/customizing-tab-behavior-for-comment-in-prolog-mode-emacs/1927/5 "2021-12-11T10:17:52Z")

</div>

Also, [the latest version (1.29)](https://bruda.ca/_media/emacs/prolog.el) has a bug, I don’t know if it exists in the old version though, is that `prolog-indent-buffer` doesn’t work properly in some cases. The root cause is that the `prolog-indent-line` may throw an error “Beginning of buffer”.

It could be work around by advising:

```prolog
(defun prolog-indent-line/around (orig-fun &rest args)
  (save-excursion
    (condition-case nil
        (apply orig-fun args)
      (beginning-of-buffer 'noindent))))

(advice-add 'prolog-indent-line :around #'prolog-indent-line/around)

```

PS. At the writing time, [Stefan Bruda’s Prolog mode for emacs](https://bruda.ca/emacs/prolog_mode_for_emacs)’ website said the prolog-mode is version 1.28, but it is actually 1.29. This may cause some confusion.
