Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8068799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:48:41+00:00 2026-06-05T12:48:41+00:00

I’m following the Douglas Crockford’s code convention , but I can’t get the correct

  • 0

I’m following the Douglas Crockford’s code convention, but I can’t get the correct identation in JS mode in Emacs. I tried to customize the indent options of the mode, tried another modes like js3, but nothing seems to work.

When I have parenthesis, and I have to break the expression, Emacs indent like this:

this.offices.each(this.addOfficesToMap,
                  this);

While the convention that I’m following, says that I should leave just 4 spaces when an expression is broken up. So the indentation should look like:

this.offices.each(this.addOfficesToMap,
    this);

Any idea of how I can change the indentation on broken up expressions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T12:48:42+00:00Added an answer on June 5, 2026 at 12:48 pm

    The behaviour you want to change is hard-coded into a function called js--proper-indentation. An inelegant fix to your problem would be to replace the function in your .emacs:

    (require 'cl)
    
    (eval-after-load "js" '(defun js--proper-indentation (parse-status)
     "Return the proper indentation for the current line."
     (save-excursion
       (back-to-indentation)
       (cond ((nth 4 parse-status)
              (js--get-c-offset 'c (nth 8 parse-status)))
             ((nth 8 parse-status) 0) ; inside string
             ((js--ctrl-statement-indentation))
             ((eq (char-after) ?#) 0)
             ((save-excursion (js--beginning-of-macro)) 4)
             ((nth 1 parse-status)
           ;; A single closing paren/bracket should be indented at the
           ;; same level as the opening statement. Same goes for
           ;; "case" and "default".
              (let ((same-indent-p (looking-at
                                    "[]})]\\|\\_<case\\_>\\|\\_<default\\_>"))
                    (continued-expr-p (js--continued-expression-p)))
                (goto-char (nth 1 parse-status)) ; go to the opening char
                (if (looking-at "[({[]\\s-*\\(/[/*]\\|$\\)")
                    (progn ; nothing following the opening paren/bracket
                      (skip-syntax-backward " ")
                      (when (eq (char-before) ?\)) (backward-list))
                      (back-to-indentation)
                      (cond (same-indent-p
                             (current-column))
                            (continued-expr-p
                             (+ (current-column) (* 2 js-indent-level)
                                js-expr-indent-offset))
                            (t
                             (+ (current-column) js-indent-level
                                (case (char-after (nth 1 parse-status))
                                  (?\( js-paren-indent-offset)
                                  (?\[ js-square-indent-offset)
                                  (?\{ js-curly-indent-offset))))))
                  ;; If there is something following the opening
                  ;; paren/bracket, everything else should be indented at
                  ;; the same level.
    
          ;; Modified code here:
                  (unless same-indent-p
                    (move-beginning-of-line 1)
                    (forward-char 4))
          ;; End modified code
                  (current-column))))
    
             ((js--continued-expression-p)
              (+ js-indent-level js-expr-indent-offset))
             (t 0))))  )
    

    I have modified three lines of code towards the bottom of the function. If you want your indentation to be 8 chars instead of 4, change the (forward-char 4) line accordingly.

    Note that js--proper-indentation (and the js library) requires the cl.el library, but that using eval-after-load mucks this up. So you need to explicitly require cl in your .emacs for this to work.

    Note that this ‘solution’ hard codes a 4 space indentation only for the situation you indicate, and does not handle nested code at all. But knowing the point in the code that deals with your situation should at least point you towards the bit that needs work for a more sophisticated solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have a French site that I want to parse, but am running into
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.