Skip to content

Commit

Permalink
Add js3-manual-indentation option
Browse files Browse the repository at this point in the history
Per sanbor's suggestion

See #39
  • Loading branch information
tamzinblake committed Jun 25, 2013
1 parent 6a3a6e2 commit b1acb5e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 16 deletions.
26 changes: 18 additions & 8 deletions js3.el
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,12 @@ regardless of the beginning bracket position."
:type 'boolean)
(js3-mark-safe-local 'js3-boring-indentation 'booleanp)

(defcustom js3-manual-indentation nil
"Non-nil to override all other indentation behavior and indent manually."
:group 'js3-mode
:type 'boolean)
(js3-mark-safe-local 'js3-manual-indentation 'booleanp)

(defcustom js3-indent-on-enter-key nil
"Non-nil to have Enter/Return key indent the line.
This is unusual for Emacs modes but common in IDEs like Eclipse."
Expand Down Expand Up @@ -10650,14 +10656,18 @@ nil."
(defun js3-indent-line ()
"Indent the current line as JavaScript."
(interactive)
(when js3-reparse-on-indent (js3-reparse))
(save-restriction
(widen)
(let* ((parse-status
(save-excursion (syntax-ppss (point-at-bol))))
(offset (- (current-column) (current-indentation))))
(indent-line-to (js3-proper-indentation parse-status))
(when (> offset 0) (forward-char offset)))))
(if js3-manual-indentation
(if js3-indent-tabs-mode
(insert "\t")
(insert-char ?\ js3-indent-level))
(when js3-reparse-on-indent (js3-reparse))
(save-restriction
(widen)
(let* ((parse-status
(save-excursion (syntax-ppss (point-at-bol))))
(offset (- (current-column) (current-indentation))))
(indent-line-to (js3-proper-indentation parse-status))
(when (> offset 0) (forward-char offset))))))

;;; js3-indent.el ends here
;;; js3-foot.el
Expand Down
20 changes: 12 additions & 8 deletions lib/js3-indent.el
Original file line number Diff line number Diff line change
Expand Up @@ -738,13 +738,17 @@ nil."
(defun js3-indent-line ()
"Indent the current line as JavaScript."
(interactive)
(when js3-reparse-on-indent (js3-reparse))
(save-restriction
(widen)
(let* ((parse-status
(save-excursion (syntax-ppss (point-at-bol))))
(offset (- (current-column) (current-indentation))))
(indent-line-to (js3-proper-indentation parse-status))
(when (> offset 0) (forward-char offset)))))
(if js3-manual-indentation
(if js3-indent-tabs-mode
(insert "\t")
(insert-char ?\ js3-indent-level))
(when js3-reparse-on-indent (js3-reparse))
(save-restriction
(widen)
(let* ((parse-status
(save-excursion (syntax-ppss (point-at-bol))))
(offset (- (current-column) (current-indentation))))
(indent-line-to (js3-proper-indentation parse-status))
(when (> offset 0) (forward-char offset))))))

;;; js3-indent.el ends here
6 changes: 6 additions & 0 deletions lib/js3-vars.el
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ regardless of the beginning bracket position."
:type 'boolean)
(js3-mark-safe-local 'js3-boring-indentation 'booleanp)

(defcustom js3-manual-indentation nil
"Non-nil to override all other indentation behavior and indent manually."
:group 'js3-mode
:type 'boolean)
(js3-mark-safe-local 'js3-manual-indentation 'booleanp)

(defcustom js3-indent-on-enter-key nil
"Non-nil to have Enter/Return key indent the line.
This is unusual for Emacs modes but common in IDEs like Eclipse."
Expand Down

0 comments on commit b1acb5e

Please sign in to comment.