unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: uu1101@gmail.com
To: 17619@debbugs.gnu.org
Subject: bug#17619: 24.3; js-indent-line mixes display position with character position
Date: Wed, 28 May 2014 20:16:39 +0200	[thread overview]
Message-ID: <86sint4vlk.fsf@gmail.com> (raw)

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





             reply	other threads:[~2014-05-28 18:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-28 18:16 uu1101 [this message]
2014-06-01  1:30 ` bug#17619: 24.3; js-indent-line mixes display position with character position Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86sint4vlk.fsf@gmail.com \
    --to=uu1101@gmail.com \
    --cc=17619@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).