Emacs prolog-mode indentation of comments

I’m using prolog.el as recommended by 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?

I’m using a slightly hacked-up version of prolog.el (here) 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?

1 Like

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!

prolog.el-1.23 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.

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

@@ -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
1 Like

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)