GNU bug report logs - #17619
24.3; js-indent-line mixes display position with character position

Previous Next

Package: emacs;

Reported by: uu1101 <at> gmail.com

Date: Wed, 28 May 2014 18:19:01 UTC

Severity: normal

Found in version 24.3

Done: Stefan Monnier <monnier <at> iro.umontreal.ca>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 17619 in the body.
You can then email your comments to 17619 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#17619; Package emacs. (Wed, 28 May 2014 18:19:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to uu1101 <at> gmail.com:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 28 May 2014 18:19:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: uu1101 <at> gmail.com
To: bug-gnu-emacs <at> gnu.org
Subject: 24.3; js-indent-line mixes display position with character position
Date: Wed, 28 May 2014 20:16:39 +0200
`js-indent-line' mixes up display column with character count. This
results in incorrect indentation when both differ. For example, I am
using the following snippet to ``prettify'' function keywords, resulting
in the characters 'function' being displayed as a single 'f':

-- >8 --
(font-lock-add-keywords
      'js-mode `(("\\(function *\\)("
                  (0 (progn (compose-region (match-beginning 1)
                                            (match-end 1) "\u0192")
                            nil)))))
-- >8 --

The current implementation of `js-indent-line' is the following:

-- >8 --
(defun js-indent-line ()
  "Indent the current line as JavaScript."
  (interactive)
  (save-restriction
    (widen)
    (let* ((parse-status
            (save-excursion (syntax-ppss (point-at-bol))))
           (offset (- (current-column) (current-indentation))))
      (indent-line-to (js--proper-indentation parse-status))
      (when (> offset 0) (forward-char offset)))))
-- >8 --

Please, notice how `current-column', which returns the _display_
position is used to calculate the offset, but then the result is used
with `forward-char' which expects a character offset instead.

I am using the following modification to work-around the issue, although
it is not correct either: it mixes character count with display offset
returned by `current-indentation'. It fixes the issue with my font-lock
customization.

-- >8 --
(defun js-indent-line ()
 "Indent the current line as JavaScript."
 (interactive)
 (save-restriction
   (widen)
   (let* ((parse-status (save-excursion (syntax-ppss (point-at-bol))))
          (current-char-position (save-excursion
                                   (let ((final (point)))
                                     (beginning-of-line)
                                     (- final (point)))))
          (offset (- current-char-position (current-indentation))))
     (indent-line-to (js--proper-indentation parse-status))
     (when (> offset 0) (forward-char offset)))))
-- >8 --
 
Best regards,
Urbano Ustero.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#17619; Package emacs. (Sun, 01 Jun 2014 01:31:02 GMT) Full text and rfc822 format available.

Message #8 received at 17619 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: uu1101 <at> gmail.com
Cc: 17619 <at> debbugs.gnu.org
Subject: Re: bug#17619: 24.3;
 js-indent-line mixes display position with character position
Date: Sat, 31 May 2014 21:30:23 -0400
> `js-indent-line' mixes up display column with character count.

Indeed.

> I am using the following modification to work-around the issue, although
[..]
>           (offset (- current-char-position (current-indentation))))

This still mixes char counts and column counts.  I used the patch
below instead.


        Stefan


=== modified file 'lisp/ChangeLog'
--- lisp/ChangeLog	2014-05-31 20:02:47 +0000
+++ lisp/ChangeLog	2014-06-01 01:27:03 +0000
@@ -1,3 +1,8 @@
+2014-06-01  Stefan Monnier  <monnier <at> iro.umontreal.ca>
+
+	* progmodes/js.el (js-indent-line): Don't mix columns and chars
+	(bug#17619).
+
 2014-05-31  Stefan Monnier  <monnier <at> iro.umontreal.ca>
 
 	* subr.el (set-transient-map): Don't wait for some "nested"

=== modified file 'lisp/progmodes/js.el'
--- lisp/progmodes/js.el	2014-05-01 23:55:25 +0000
+++ lisp/progmodes/js.el	2014-06-01 01:29:02 +0000
@@ -1907,7 +1907,7 @@
   (interactive)
   (let* ((parse-status
           (save-excursion (syntax-ppss (point-at-bol))))
-         (offset (- (current-column) (current-indentation))))
+         (offset (- (point) (save-excursion (back-to-indentation) (point)))))
     (indent-line-to (js--proper-indentation parse-status))
     (when (> offset 0) (forward-char offset))))
 





bug closed, send any further explanations to 17619 <at> debbugs.gnu.org and uu1101 <at> gmail.com Request was from Stefan Monnier <monnier <at> iro.umontreal.ca> to control <at> debbugs.gnu.org. (Sun, 01 Jun 2014 01:54:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 29 Jun 2014 11:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 10 years and 361 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.