Skip to content

Commit

Permalink
Merge pull request #82 from notetiene/master
Browse files Browse the repository at this point in the history
Customize preferred quotes
  • Loading branch information
NicolasPetton authored Oct 19, 2016
2 parents 71fc914 + 56eea9a commit 1d15ffd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
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

0 comments on commit 1d15ffd

Please sign in to comment.