# Emacs prolog-mode indentation of comments

**URL:** <https://swi-prolog.discourse.group/t/emacs-prolog-mode-indentation-of-comments/1048>\
**Category:** Help!\
**Created:** [August 9, 2019, 2:03am UTC](https://swi-prolog.discourse.group/t/emacs-prolog-mode-indentation-of-comments/1048 "2019-08-09T02:03:25Z")\
**Posts on this page:** 5\
**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:** [August 9, 2019, 2:03am UTC](https://swi-prolog.discourse.group/t/emacs-prolog-mode-indentation-of-comments/1048/1 "2019-08-09T02:03:26Z")

</div>

I’m using `prolog.el` as recommended by [https://www.swi-prolog.org/FAQ/GnuEmacs.html](https://www.swi-prolog.org/FAQ/GnuEmacs.html)

One annoyance is that when a line starts with a single “`%`” and I hit “tab” (which is bound to `indent-for-tab-command`), it indents 32 spaces. I can turn this off by using a double “`%%`”. (This seems to be related to the behavior for same-line comments, which align at column 32.)  
I’ve looked at the `prolog.el` code but can’t figure out how to change this behavior. Suggestions?

---

<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:** [August 9, 2019, 7:08pm UTC](https://swi-prolog.discourse.group/t/emacs-prolog-mode-indentation-of-comments/1048/2 "2019-08-09T19:08:10Z")

</div>

I’m using a slightly hacked-up version of prolog.el ([here](https://github.com/jamesnvc/dotfiles/blob/9995d583b491d65d350611ee68ca8b0809300e1e/emacs.d/modules/prolog.el)) but I don’t seem to be experiencing that indent issue…I have made modifications, but just to the indentation for `0'c` constructs and dictionaries. Is it possible there’s some other Emacs setting governing that?

---

<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:** [August 9, 2019, 7:49pm UTC](https://swi-prolog.discourse.group/t/emacs-prolog-mode-indentation-of-comments/1048/3 "2019-08-09T19:49:51Z")

</div>

> [@jamesnvc](#):
>
> I’m using a slightly hacked-up version of prolog.el ([here](https://github.com/jamesnvc/dotfiles/blob/9995d583b491d65d350611ee68ca8b0809300e1e/emacs.d/modules/prolog.el))

Your version is based on prolog.el-1.23 (the current version is 1.27) … and it doesn’t exhibit the indent problem. So, I can try finding older versions of prolog.el and identify where things changed. Thanks!

---

<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:** [April 20, 2020, 8:50pm UTC](https://swi-prolog.discourse.group/t/emacs-prolog-mode-indentation-of-comments/1048/4 "2020-04-20T20:50:59Z")

</div>

[prolog.el-1.23](http://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/progmodes/prolog.el) that comes with Emacs doesn’t indent lines starting with “%” any differently than lines starting with “%%”. There are a _lot_ of changes between it and [Stefan Bruda’s version](https://bruda.ca/emacs/prolog_mode_for_emacs).

Anyway, this quick 2-line change fixed the problem (and probably broke some other things):

```prolog
@@ -1990,18 +1990,19 @@ rigidly along with this one (not yet)."
     ;; Insert spaces if needed
     (if (or prolog-electric-tab-flag prolog-electric-if-then-else-flag)
         (prolog-insert-spaces-after-paren))
     ))
 
 (defun prolog-comment-indent ()
   "Compute prolog comment indentation."
   (cond ((looking-at "%%%") (prolog-indentation-level-of-line))
         ((looking-at "%%") (prolog-indent-level))
+ ((looking-at "%") (prolog-indent-level)) ;; HACK <===========
         (t
          (save-excursion
            (skip-chars-backward " \t")
            ;; Insert one space at least, except at left margin.
            (max (+ (current-column) (if (bolp) 0 1))
                 comment-column)))
         ))
 
 (defun prolog-indent-level ()
@@ -2009,19 +2010,19 @@ rigidly along with this one (not yet)."
   (save-excursion
     (beginning-of-line)
     (let ((totbal (prolog-region-paren-balance
                    (prolog-clause-start t) (point)))
           (oldpoint (point)))
       (skip-chars-forward " \t")
       (cond
        ((looking-at "%%%") (prolog-indentation-level-of-line))
                                         ;Large comment starts
- ((looking-at "%[^%]") comment-column) ;Small comment starts
+ ;; ((looking-at "%[^%]") comment-column) ;Small comment starts % HACK (removed) <=====
        ((bobp) 0) ;Beginning of buffer
 
        ;; If we found '}' then we must check if it's the
        ;; end of an object declaration or something else.
        ((and (looking-at "}") 
              (save-excursion
                (forward-char 1)
                ;; Goto to matching {
                (if prolog-use-prolog-tokenizer-flag

```

---

<div class="post-metadata">

**Author:** ![emacstheviking](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/emacstheviking/32/228_2.png) [@emacstheviking](https://swi-prolog.discourse.group/u/emacstheviking)\
**Post date:** [June 12, 2020, 11:03pm UTC](https://swi-prolog.discourse.group/t/emacs-prolog-mode-indentation-of-comments/1048/5 "2020-06-12T23:03:38Z")

</div>

Ironically I just hit this same problem!!! I am using version 0.1.31

My workaround is

> ```
> M-x set-variable
> comment-column
> 0
> 
> ```

I actually have this in me ~/.emacs file but it seems to be not having any effect

> (setq comment-column 0)
