                            er/mark-inside-pairs
                            er/mark-outside-pairs))
 
-;; Add more methods for javascript
+;; Add more methods for JavaScript
+
+(defun er/mark-js-function ()
+  (interactive)
+  (condition-case nil
+      (forward-char 8)
+    (error nil))
+  (word-search-backward "function")
+  (set-mark (point))
+  (while (not (looking-at "{"))
+    (forward-char))
+  (forward-list)
+  (exchange-point-and-mark))
+
+(defun er/mark-js-outer-return ()
+  (interactive)
+  (condition-case nil
+      (forward-char 6)
+    (error nil))
+  (word-search-backward "return")
+  (set-mark (point))
+  (while (not (looking-at ";"))
+    (if (looking-at "\\s(")
+        (forward-list)
+      (forward-char)))
+  (forward-char)
+  (exchange-point-and-mark))
+
+(defun er/mark-js-inner-return ()
+  (interactive)
+  (condition-case nil
+      (forward-char 6)
+    (error nil))
+  (word-search-backward "return")
+  (search-forward " ")
+  (set-mark (point))
+  (while (not (looking-at ";"))
+    (if (looking-at "\\s(")
+        (forward-list)
+      (forward-char)))
+  (exchange-point-and-mark))
+
+(defun er/mark-js-if ()
+  (interactive)
+  (condition-case nil
+      (forward-char 2)
+    (error nil))
+  (word-search-backward "if")
+  (set-mark (point))
+  (while (not (looking-at "("))
+    (forward-char))
+  (forward-list)
+  (while (not (looking-at "{"))
+    (forward-char))
+  (forward-list)
+  (exchange-point-and-mark))
 
 (defun er/more-expansions-in-js2-mode ()
   (make-variable-buffer-local 'er/try-expand-list)
   (setq er/try-expand-list (append
                             er/try-expand-list
-                            '(er/mark-js-function))))
+                            '(er/mark-js-function
+                              er/mark-js-if
+                              er/mark-js-inner-return
+                              er/mark-js-outer-return))))
 
 (add-hook 'js2-mode-hook 'er/more-expansions-in-js2-mode)
 

          (forward-list))
      (exchange-point-and-mark))))

;; Mark javascript function

(defun er/mark-js-function ()
  (interactive)
  (while (not (looking-at "function "))
    (backward-char))
  (set-mark (point))
  (while (not (looking-at "{"))
    (forward-char))
  (forward-list)
  (exchange-point-and-mark))

;; Quotes

(defun current-quotes-char ()

    (set-mark best-end)))

(provide 'expand-region)



;; Todo: Take advantage of this:
;;
;; Well, in a nutshell, he makes the inspired assumption that indentation is
;; almost always a function of brace/paren/curly nesting level, and he uses a
;; little-known built-in Emacs function called parse-partial-sexp, written in C,
;; which tells you the current nesting level of not only braces, parens and
;; curlies, but also of c-style block comments, and whether you're inside a
;; single- or double-quoted string. How useful! Good thing JavaScript uses
;; C-like syntax, or that function would have been far less relevant.
