Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customize preferred quotes #82

Merged
merged 3 commits into from
Oct 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions js2-refactor.el
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,22 @@

;;; Settings ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defvar js2r-use-strict nil
"When non-nil, js2r inserts strict declarations in IIFEs.")
(defgroup js2-refactor nil
"Minor mode providing JavaScript refactorings."
:group 'tools
:prefix "js2r-"
:link '(url-link :tag "Repository" "https://github.com/magnars/js2-refactor.el"))

(defcustom js2r-use-strict nil
"When non-nil, js2r inserts strict declarations in IIFEs."
:group 'js2-refactor
:type 'boolean)

(defcustom js2r-prefered-quote-type 1
"The prefered quote style for strings."
:group 'js2-refactor
:type '(choice (const :tag "Double" 1)
(const :tag "Single" 2)))

;;; Keybindings ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Expand Down
4 changes: 2 additions & 2 deletions js2r-conveniences.el
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
(when (looking-at "[;{]")
(forward-char 1))
(newline-and-indent)
(insert "console.log(\"" stmt " = \", " stmt ");"))))
(insert "console.log(" (js2r--wrap-text stmt " = ") ", " stmt ");"))))

(defun js2r-debug-this ()
"Debug the node at point, adding a 'debug()' statement."
Expand All @@ -56,7 +56,7 @@
(when (looking-at "[;{]")
(forward-char 1))
(newline-and-indent)
(insert "debug(\"" stmt " = %s\", " stmt ");"))))
(insert "debug(" (js2r--wrap-text stmt " = %s") ", " stmt ");"))))

(defun js2r--figure-out-what-to-log-where ()
"Return a dotted pair containing the statement to log and the
Expand Down
7 changes: 7 additions & 0 deletions js2r-helpers.el
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
(require 'dash)
(require 's)

(defun js2r--wrap-text (&rest text)
"Wrap TEXT with the prefered quotes. The prefered quotes is set with `js2r-prefered-quote-type'."
(let ((prefered-quotes "\""))
(when (= 2 js2r-prefered-quote-type)
(setq prefered-quotes "'"))
(concat prefered-quotes (apply 'concat text) prefered-quotes)))

(defun js2r--fix-special-modifier-combinations (key)
(case key
("C-s-i" "s-TAB")
Expand Down