unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#17619: 24.3; js-indent-line mixes display position with character position
@ 2014-05-28 18:16 uu1101
  2014-06-01  1:30 ` Stefan Monnier
  0 siblings, 1 reply; 2+ messages in thread
From: uu1101 @ 2014-05-28 18:16 UTC (permalink / raw)
  To: 17619

`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.





^ permalink raw reply	[flat|nested] 2+ messages in thread

* bug#17619: 24.3; js-indent-line mixes display position with character position
  2014-05-28 18:16 bug#17619: 24.3; js-indent-line mixes display position with character position uu1101
@ 2014-06-01  1:30 ` Stefan Monnier
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Monnier @ 2014-06-01  1:30 UTC (permalink / raw)
  To: uu1101; +Cc: 17619

> `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@iro.umontreal.ca>
+
+	* progmodes/js.el (js-indent-line): Don't mix columns and chars
+	(bug#17619).
+
 2014-05-31  Stefan Monnier  <monnier@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))))
 






^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-06-01  1:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-28 18:16 bug#17619: 24.3; js-indent-line mixes display position with character position uu1101
2014-06-01  1:30 ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).