2012-04-26 08:43:28 -04:00
|
|
|
|
;;; js.el --- Major mode for editing JavaScript -*- lexical-binding: t -*-
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
2019-01-01 00:59:58 +00:00
|
|
|
|
;; Copyright (C) 2008-2019 Free Software Foundation, Inc.
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
;; Author: Karl Landstrom <karl.landstrom@brgeight.se>
|
|
|
|
|
;; Daniel Colascione <dan.colascione@gmail.com>
|
|
|
|
|
;; Maintainer: Daniel Colascione <dan.colascione@gmail.com>
|
|
|
|
|
;; Version: 9
|
|
|
|
|
;; Date: 2009-07-25
|
2010-08-29 12:17:13 -04:00
|
|
|
|
;; Keywords: languages, javascript
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2017-09-13 15:52:52 -07:00
|
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
;;; Commentary
|
|
|
|
|
|
|
|
|
|
;; This is based on Karl Landstrom's barebones javascript-mode. This
|
|
|
|
|
;; is much more robust and works with cc-mode's comment filling
|
|
|
|
|
;; (mostly).
|
|
|
|
|
;;
|
|
|
|
|
;; The main features of this JavaScript mode are syntactic
|
|
|
|
|
;; highlighting (enabled with `font-lock-mode' or
|
|
|
|
|
;; `global-font-lock-mode'), automatic indentation and filling of
|
|
|
|
|
;; comments, C preprocessor fontification, and MozRepl integration.
|
|
|
|
|
;;
|
|
|
|
|
;; General Remarks:
|
|
|
|
|
;;
|
|
|
|
|
;; XXX: This mode assumes that block comments are not nested inside block
|
|
|
|
|
;; XXX: comments
|
|
|
|
|
;;
|
|
|
|
|
;; Exported names start with "js-"; private names start with
|
|
|
|
|
;; "js--".
|
|
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
2010-09-08 18:21:23 +02:00
|
|
|
|
(require 'cc-mode)
|
|
|
|
|
(require 'newcomment)
|
|
|
|
|
(require 'imenu)
|
|
|
|
|
(require 'moz nil t)
|
2019-01-08 12:37:22 +08:00
|
|
|
|
(require 'json)
|
2017-03-23 11:33:22 -06:00
|
|
|
|
(require 'prog-mode)
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(eval-when-compile
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(require 'cl-lib)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
(require 'ido))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defvar inferior-moz-buffer)
|
|
|
|
|
(defvar moz-repl-name)
|
|
|
|
|
(defvar ido-cur-list)
|
2011-08-12 11:32:39 -04:00
|
|
|
|
(defvar electric-layout-rules)
|
2016-05-26 13:38:28 -07:00
|
|
|
|
(declare-function ido-mode "ido" (&optional arg))
|
2009-08-21 07:44:58 +00:00
|
|
|
|
(declare-function inferior-moz-process "ext:mozrepl" ())
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
;;; Constants
|
|
|
|
|
|
2019-03-08 16:29:02 -08:00
|
|
|
|
(defconst js--name-start-chars "a-zA-Z_$"
|
|
|
|
|
"Character class chars matching the start of a JavaScript identifier.")
|
|
|
|
|
|
|
|
|
|
(defconst js--name-start-re (concat "[" js--name-start-chars "]")
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Regexp matching the start of a JavaScript identifier, without grouping.")
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defconst js--stmt-delim-chars "^;{}?:")
|
|
|
|
|
|
|
|
|
|
(defconst js--name-re (concat js--name-start-re
|
|
|
|
|
"\\(?:\\s_\\|\\sw\\)*")
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Regexp matching a JavaScript identifier, without grouping.")
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defconst js--objfield-re (concat js--name-re ":")
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Regexp matching the start of a JavaScript object field.")
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defconst js--dotted-name-re
|
|
|
|
|
(concat js--name-re "\\(?:\\." js--name-re "\\)*")
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Regexp matching a dot-separated sequence of JavaScript names.")
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defconst js--cpp-name-re js--name-re
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Regexp matching a C preprocessor name.")
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defconst js--opt-cpp-start "^\\s-*#\\s-*\\([[:alnum:]]+\\)"
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Regexp matching the prefix of a cpp directive.
|
|
|
|
|
This includes the directive name, or nil in languages without
|
|
|
|
|
preprocessor support. The first submatch surrounds the directive
|
|
|
|
|
name.")
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defconst js--plain-method-re
|
|
|
|
|
(concat "^\\s-*?\\(" js--dotted-name-re "\\)\\.prototype"
|
|
|
|
|
"\\.\\(" js--name-re "\\)\\s-*?=\\s-*?\\(function\\)\\_>")
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Regexp matching an explicit JavaScript prototype \"method\" declaration.
|
* international/ucs-normalize.el (ucs-normalize-sort, quick-check-list):
Fix typos in docstrings.
* progmodes/js.el (js--macro-decl-re): Doc fix.
(js--plain-method-re, js--split-name): Refloc docstring.
(js--class-styles, js--make-merged-item, js--splice-into-items):
Fix typos in docstrings; reflow docstrings.
(js--maybe-join, js--function-prologue-beginning, js--flush-caches)
(js--variable-decl-matcher, js--inside-pitem-p)
(js--parse-state-at-point, js--get-all-known-symbols)
(js--symbol-history, js-find-symbol, js--js-references)
(js--moz-interactor, js--js-encode-value, js--read-tab):
Fix typos in docstrings.
2009-08-28 18:22:30 +00:00
|
|
|
|
Group 1 is a (possibly-dotted) class name, group 2 is a method name,
|
2015-11-17 15:28:50 -08:00
|
|
|
|
and group 3 is the `function' keyword.")
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defconst js--plain-class-re
|
|
|
|
|
(concat "^\\s-*\\(" js--dotted-name-re "\\)\\.prototype"
|
|
|
|
|
"\\s-*=\\s-*{")
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Regexp matching a JavaScript explicit prototype \"class\" declaration.
|
|
|
|
|
An example of this is \"Class.prototype = { method1: ...}\".")
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
2009-08-15 01:04:14 +00:00
|
|
|
|
;; var NewClass = BaseClass.extend(
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(defconst js--mp-class-decl-re
|
|
|
|
|
(concat "^\\s-*var\\s-+"
|
|
|
|
|
"\\(" js--name-re "\\)"
|
|
|
|
|
"\\s-*=\\s-*"
|
|
|
|
|
"\\(" js--dotted-name-re
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"\\)\\.extend\\(?:Final\\)?\\s-*(\\s-*{?\\s-*$"))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
2009-08-15 01:04:14 +00:00
|
|
|
|
;; var NewClass = Class.create()
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(defconst js--prototype-obsolete-class-decl-re
|
|
|
|
|
(concat "^\\s-*\\(?:var\\s-+\\)?"
|
|
|
|
|
"\\(" js--dotted-name-re "\\)"
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"\\s-*=\\s-*Class\\.create()"))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defconst js--prototype-objextend-class-decl-re-1
|
|
|
|
|
(concat "^\\s-*Object\\.extend\\s-*("
|
|
|
|
|
"\\(" js--dotted-name-re "\\)"
|
|
|
|
|
"\\s-*,\\s-*{"))
|
|
|
|
|
|
|
|
|
|
(defconst js--prototype-objextend-class-decl-re-2
|
|
|
|
|
(concat "^\\s-*\\(?:var\\s-+\\)?"
|
|
|
|
|
"\\(" js--dotted-name-re "\\)"
|
2015-09-17 16:08:20 -07:00
|
|
|
|
"\\s-*=\\s-*Object\\.extend\\s-*("))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
2009-08-15 01:04:14 +00:00
|
|
|
|
;; var NewClass = Class.create({
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(defconst js--prototype-class-decl-re
|
|
|
|
|
(concat "^\\s-*\\(?:var\\s-+\\)?"
|
|
|
|
|
"\\(" js--name-re "\\)"
|
|
|
|
|
"\\s-*=\\s-*Class\\.create\\s-*(\\s-*"
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"\\(?:\\(" js--dotted-name-re "\\)\\s-*,\\s-*\\)?{?"))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
2009-08-15 01:04:14 +00:00
|
|
|
|
;; Parent class name(s) (yes, multiple inheritance in JavaScript) are
|
2009-08-14 23:02:38 +00:00
|
|
|
|
;; matched with dedicated font-lock matchers
|
|
|
|
|
(defconst js--dojo-class-decl-re
|
|
|
|
|
(concat "^\\s-*dojo\\.declare\\s-*(\"\\(" js--dotted-name-re "\\)"))
|
|
|
|
|
|
|
|
|
|
(defconst js--extjs-class-decl-re-1
|
|
|
|
|
(concat "^\\s-*Ext\\.extend\\s-*("
|
|
|
|
|
"\\s-*\\(" js--dotted-name-re "\\)"
|
|
|
|
|
"\\s-*,\\s-*\\(" js--dotted-name-re "\\)")
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Regexp matching an ExtJS class declaration (style 1).")
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defconst js--extjs-class-decl-re-2
|
|
|
|
|
(concat "^\\s-*\\(?:var\\s-+\\)?"
|
|
|
|
|
"\\(" js--name-re "\\)"
|
|
|
|
|
"\\s-*=\\s-*Ext\\.extend\\s-*(\\s-*"
|
|
|
|
|
"\\(" js--dotted-name-re "\\)")
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Regexp matching an ExtJS class declaration (style 2).")
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defconst js--mochikit-class-re
|
|
|
|
|
(concat "^\\s-*MochiKit\\.Base\\.update\\s-*(\\s-*"
|
|
|
|
|
"\\(" js--dotted-name-re "\\)")
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Regexp matching a MochiKit class declaration.")
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defconst js--dummy-class-style
|
|
|
|
|
'(:name "[Automatically Generated Class]"))
|
|
|
|
|
|
|
|
|
|
(defconst js--class-styles
|
|
|
|
|
`((:name "Plain"
|
|
|
|
|
:class-decl ,js--plain-class-re
|
|
|
|
|
:prototype t
|
|
|
|
|
:contexts (toplevel)
|
|
|
|
|
:framework javascript)
|
|
|
|
|
|
|
|
|
|
(:name "MochiKit"
|
|
|
|
|
:class-decl ,js--mochikit-class-re
|
|
|
|
|
:prototype t
|
|
|
|
|
:contexts (toplevel)
|
|
|
|
|
:framework mochikit)
|
|
|
|
|
|
|
|
|
|
(:name "Prototype (Obsolete)"
|
|
|
|
|
:class-decl ,js--prototype-obsolete-class-decl-re
|
|
|
|
|
:contexts (toplevel)
|
|
|
|
|
:framework prototype)
|
|
|
|
|
|
|
|
|
|
(:name "Prototype (Modern)"
|
|
|
|
|
:class-decl ,js--prototype-class-decl-re
|
|
|
|
|
:contexts (toplevel)
|
|
|
|
|
:framework prototype)
|
|
|
|
|
|
|
|
|
|
(:name "Prototype (Object.extend)"
|
|
|
|
|
:class-decl ,js--prototype-objextend-class-decl-re-1
|
|
|
|
|
:prototype t
|
|
|
|
|
:contexts (toplevel)
|
|
|
|
|
:framework prototype)
|
|
|
|
|
|
|
|
|
|
(:name "Prototype (Object.extend) 2"
|
|
|
|
|
:class-decl ,js--prototype-objextend-class-decl-re-2
|
|
|
|
|
:prototype t
|
|
|
|
|
:contexts (toplevel)
|
|
|
|
|
:framework prototype)
|
|
|
|
|
|
|
|
|
|
(:name "Dojo"
|
|
|
|
|
:class-decl ,js--dojo-class-decl-re
|
|
|
|
|
:contexts (toplevel)
|
|
|
|
|
:framework dojo)
|
|
|
|
|
|
|
|
|
|
(:name "ExtJS (style 1)"
|
|
|
|
|
:class-decl ,js--extjs-class-decl-re-1
|
|
|
|
|
:prototype t
|
|
|
|
|
:contexts (toplevel)
|
|
|
|
|
:framework extjs)
|
|
|
|
|
|
|
|
|
|
(:name "ExtJS (style 2)"
|
|
|
|
|
:class-decl ,js--extjs-class-decl-re-2
|
|
|
|
|
:contexts (toplevel)
|
|
|
|
|
:framework extjs)
|
|
|
|
|
|
|
|
|
|
(:name "Merrill Press"
|
|
|
|
|
:class-decl ,js--mp-class-decl-re
|
|
|
|
|
:contexts (toplevel)
|
|
|
|
|
:framework merrillpress))
|
|
|
|
|
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"List of JavaScript class definition styles.
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
A class definition style is a plist with the following keys:
|
|
|
|
|
|
|
|
|
|
:name is a human-readable name of the class type
|
|
|
|
|
|
|
|
|
|
:class-decl is a regular expression giving the start of the
|
* international/ucs-normalize.el (ucs-normalize-sort, quick-check-list):
Fix typos in docstrings.
* progmodes/js.el (js--macro-decl-re): Doc fix.
(js--plain-method-re, js--split-name): Refloc docstring.
(js--class-styles, js--make-merged-item, js--splice-into-items):
Fix typos in docstrings; reflow docstrings.
(js--maybe-join, js--function-prologue-beginning, js--flush-caches)
(js--variable-decl-matcher, js--inside-pitem-p)
(js--parse-state-at-point, js--get-all-known-symbols)
(js--symbol-history, js-find-symbol, js--js-references)
(js--moz-interactor, js--js-encode-value, js--read-tab):
Fix typos in docstrings.
2009-08-28 18:22:30 +00:00
|
|
|
|
class. Its first group must match the name of its class. If there
|
|
|
|
|
is a parent class, the second group should match, and it should be
|
|
|
|
|
the name of the class.
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
If :prototype is present and non-nil, the parser will merge
|
|
|
|
|
declarations for this constructs with others at the same lexical
|
* international/ucs-normalize.el (ucs-normalize-sort, quick-check-list):
Fix typos in docstrings.
* progmodes/js.el (js--macro-decl-re): Doc fix.
(js--plain-method-re, js--split-name): Refloc docstring.
(js--class-styles, js--make-merged-item, js--splice-into-items):
Fix typos in docstrings; reflow docstrings.
(js--maybe-join, js--function-prologue-beginning, js--flush-caches)
(js--variable-decl-matcher, js--inside-pitem-p)
(js--parse-state-at-point, js--get-all-known-symbols)
(js--symbol-history, js-find-symbol, js--js-references)
(js--moz-interactor, js--js-encode-value, js--read-tab):
Fix typos in docstrings.
2009-08-28 18:22:30 +00:00
|
|
|
|
level that have the same name. Otherwise, multiple definitions
|
|
|
|
|
will create multiple top-level entries. Don't use :prototype
|
2009-08-14 23:02:38 +00:00
|
|
|
|
unnecessarily: it has an associated cost in performance.
|
|
|
|
|
|
|
|
|
|
If :strip-prototype is present and non-nil, then if the class
|
|
|
|
|
name as matched contains
|
|
|
|
|
")
|
|
|
|
|
|
|
|
|
|
(defconst js--available-frameworks
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cl-loop for style in js--class-styles
|
|
|
|
|
for framework = (plist-get style :framework)
|
|
|
|
|
unless (memq framework available-frameworks)
|
|
|
|
|
collect framework into available-frameworks
|
|
|
|
|
finally return available-frameworks)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"List of available JavaScript frameworks symbols.")
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defconst js--function-heading-1-re
|
|
|
|
|
(concat
|
2015-01-09 10:25:50 -08:00
|
|
|
|
"^\\s-*function\\(?:\\s-\\|\\*\\)+\\(" js--name-re "\\)")
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Regexp matching the start of a JavaScript function header.
|
|
|
|
|
Match group 1 is the name of the function.")
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defconst js--function-heading-2-re
|
|
|
|
|
(concat
|
|
|
|
|
"^\\s-*\\(" js--name-re "\\)\\s-*:\\s-*function\\_>")
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Regexp matching the start of a function entry in an associative array.
|
|
|
|
|
Match group 1 is the name of the function.")
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defconst js--function-heading-3-re
|
|
|
|
|
(concat
|
|
|
|
|
"^\\s-*\\(?:var\\s-+\\)?\\(" js--dotted-name-re "\\)"
|
|
|
|
|
"\\s-*=\\s-*function\\_>")
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Regexp matching a line in the JavaScript form \"var MUMBLE = function\".
|
|
|
|
|
Match group 1 is MUMBLE.")
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defconst js--macro-decl-re
|
|
|
|
|
(concat "^\\s-*#\\s-*define\\s-+\\(" js--cpp-name-re "\\)\\s-*(")
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Regexp matching a CPP macro definition, up to the opening parenthesis.
|
* international/ucs-normalize.el (ucs-normalize-sort, quick-check-list):
Fix typos in docstrings.
* progmodes/js.el (js--macro-decl-re): Doc fix.
(js--plain-method-re, js--split-name): Refloc docstring.
(js--class-styles, js--make-merged-item, js--splice-into-items):
Fix typos in docstrings; reflow docstrings.
(js--maybe-join, js--function-prologue-beginning, js--flush-caches)
(js--variable-decl-matcher, js--inside-pitem-p)
(js--parse-state-at-point, js--get-all-known-symbols)
(js--symbol-history, js-find-symbol, js--js-references)
(js--moz-interactor, js--js-encode-value, js--read-tab):
Fix typos in docstrings.
2009-08-28 18:22:30 +00:00
|
|
|
|
Match group 1 is the name of the macro.")
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defun js--regexp-opt-symbol (list)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Like `regexp-opt', but surround the result with `\\\\_<' and `\\\\_>'."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(concat "\\_<" (regexp-opt list t) "\\_>"))
|
|
|
|
|
|
|
|
|
|
(defconst js--keyword-re
|
|
|
|
|
(js--regexp-opt-symbol
|
2017-02-23 23:57:59 -07:00
|
|
|
|
'("abstract" "async" "await" "break" "case" "catch" "class" "const"
|
2009-08-14 23:02:38 +00:00
|
|
|
|
"continue" "debugger" "default" "delete" "do" "else"
|
|
|
|
|
"enum" "export" "extends" "final" "finally" "for"
|
|
|
|
|
"function" "goto" "if" "implements" "import" "in"
|
|
|
|
|
"instanceof" "interface" "native" "new" "package"
|
|
|
|
|
"private" "protected" "public" "return" "static"
|
|
|
|
|
"super" "switch" "synchronized" "throw"
|
|
|
|
|
"throws" "transient" "try" "typeof" "var" "void" "let"
|
|
|
|
|
"yield" "volatile" "while" "with"))
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Regexp matching any JavaScript keyword.")
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defconst js--basic-type-re
|
|
|
|
|
(js--regexp-opt-symbol
|
|
|
|
|
'("boolean" "byte" "char" "double" "float" "int" "long"
|
|
|
|
|
"short" "void"))
|
|
|
|
|
"Regular expression matching any predefined type in JavaScript.")
|
|
|
|
|
|
|
|
|
|
(defconst js--constant-re
|
|
|
|
|
(js--regexp-opt-symbol '("false" "null" "undefined"
|
|
|
|
|
"Infinity" "NaN"
|
|
|
|
|
"true" "arguments" "this"))
|
|
|
|
|
"Regular expression matching any future reserved words in JavaScript.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defconst js--font-lock-keywords-1
|
|
|
|
|
(list
|
|
|
|
|
"\\_<import\\_>"
|
|
|
|
|
(list js--function-heading-1-re 1 font-lock-function-name-face)
|
|
|
|
|
(list js--function-heading-2-re 1 font-lock-function-name-face))
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Level one font lock keywords for `js-mode'.")
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defconst js--font-lock-keywords-2
|
|
|
|
|
(append js--font-lock-keywords-1
|
|
|
|
|
(list (list js--keyword-re 1 font-lock-keyword-face)
|
|
|
|
|
(list "\\_<for\\_>"
|
|
|
|
|
"\\s-+\\(each\\)\\_>" nil nil
|
|
|
|
|
(list 1 'font-lock-keyword-face))
|
|
|
|
|
(cons js--basic-type-re font-lock-type-face)
|
|
|
|
|
(cons js--constant-re font-lock-constant-face)))
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Level two font lock keywords for `js-mode'.")
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
;; js--pitem is the basic building block of the lexical
|
|
|
|
|
;; database. When one refers to a real part of the buffer, the region
|
|
|
|
|
;; of text to which it refers is split into a conceptual header and
|
|
|
|
|
;; body. Consider the (very short) block described by a hypothetical
|
|
|
|
|
;; js--pitem:
|
|
|
|
|
;;
|
|
|
|
|
;; function foo(a,b,c) { return 42; }
|
|
|
|
|
;; ^ ^ ^
|
|
|
|
|
;; | | |
|
|
|
|
|
;; +- h-begin +- h-end +- b-end
|
|
|
|
|
;;
|
|
|
|
|
;; (Remember that these are buffer positions, and therefore point
|
|
|
|
|
;; between characters, not at them. An arrow drawn to a character
|
|
|
|
|
;; indicates the corresponding position is between that character and
|
|
|
|
|
;; the one immediately preceding it.)
|
|
|
|
|
;;
|
|
|
|
|
;; The header is the region of text [h-begin, h-end], and is
|
|
|
|
|
;; the text needed to unambiguously recognize the start of the
|
|
|
|
|
;; construct. If the entire header is not present, the construct is
|
|
|
|
|
;; not recognized at all. No other pitems may be nested inside the
|
|
|
|
|
;; header.
|
|
|
|
|
;;
|
|
|
|
|
;; The body is the region [h-end, b-end]. It may contain nested
|
|
|
|
|
;; js--pitem instances. The body of a pitem may be empty: in
|
|
|
|
|
;; that case, b-end is equal to header-end.
|
|
|
|
|
;;
|
|
|
|
|
;; The three points obey the following relationship:
|
|
|
|
|
;;
|
|
|
|
|
;; h-begin < h-end <= b-end
|
|
|
|
|
;;
|
|
|
|
|
;; We put a text property in the buffer on the character *before*
|
|
|
|
|
;; h-end, and if we see it, on the character *before* b-end.
|
|
|
|
|
;;
|
|
|
|
|
;; The text property for h-end, js--pstate, is actually a list
|
|
|
|
|
;; of all js--pitem instances open after the marked character.
|
|
|
|
|
;;
|
|
|
|
|
;; The text property for b-end, js--pend, is simply the
|
|
|
|
|
;; js--pitem that ends after the marked character. (Because
|
|
|
|
|
;; pitems always end when the paren-depth drops below a critical
|
|
|
|
|
;; value, and because we can only drop one level per character, only
|
|
|
|
|
;; one pitem may end at a given character.)
|
|
|
|
|
;;
|
|
|
|
|
;; In the structure below, we only store h-begin and (sometimes)
|
|
|
|
|
;; b-end. We can trivially and quickly find h-end by going to h-begin
|
|
|
|
|
;; and searching for an js--pstate text property. Since no other
|
|
|
|
|
;; js--pitem instances can be nested inside the header of a
|
|
|
|
|
;; pitem, the location after the character with this text property
|
|
|
|
|
;; must be h-end.
|
|
|
|
|
;;
|
|
|
|
|
;; js--pitem instances are never modified (with the exception
|
2011-12-30 17:27:15 -08:00
|
|
|
|
;; of the b-end field). Instead, modified copies are added at
|
|
|
|
|
;; subsequence parse points.
|
2009-08-14 23:02:38 +00:00
|
|
|
|
;; (The exception for b-end and its caveats is described below.)
|
|
|
|
|
;;
|
|
|
|
|
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cl-defstruct (js--pitem (:type list))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
;; IMPORTANT: Do not alter the position of fields within the list.
|
|
|
|
|
;; Various bits of code depend on their positions, particularly
|
|
|
|
|
;; anything that manipulates the list of children.
|
|
|
|
|
|
|
|
|
|
;; List of children inside this pitem's body
|
|
|
|
|
(children nil :read-only t)
|
|
|
|
|
|
|
|
|
|
;; When we reach this paren depth after h-end, the pitem ends
|
|
|
|
|
(paren-depth nil :read-only t)
|
|
|
|
|
|
|
|
|
|
;; Symbol or class-style plist if this is a class
|
|
|
|
|
(type nil :read-only t)
|
|
|
|
|
|
|
|
|
|
;; See above
|
|
|
|
|
(h-begin nil :read-only t)
|
|
|
|
|
|
|
|
|
|
;; List of strings giving the parts of the name of this pitem (e.g.,
|
|
|
|
|
;; '("MyClass" "myMethod"), or t if this pitem is anonymous
|
|
|
|
|
(name nil :read-only t)
|
|
|
|
|
|
|
|
|
|
;; THIS FIELD IS MUTATED, and its value is shared by all copies of
|
|
|
|
|
;; this pitem: when we copy-and-modify pitem instances, we share
|
|
|
|
|
;; their tail structures, so all the copies actually have the same
|
|
|
|
|
;; terminating cons cell. We modify that shared cons cell directly.
|
|
|
|
|
;;
|
|
|
|
|
;; The field value is either a number (buffer location) or nil if
|
|
|
|
|
;; unknown.
|
|
|
|
|
;;
|
|
|
|
|
;; If the field's value is greater than `js--cache-end', the
|
|
|
|
|
;; value is stale and must be treated as if it were nil. Conversely,
|
|
|
|
|
;; if this field is nil, it is guaranteed that this pitem is open up
|
|
|
|
|
;; to at least `js--cache-end'. (This property is handy when
|
|
|
|
|
;; computing whether we're inside a given pitem.)
|
|
|
|
|
;;
|
|
|
|
|
(b-end nil))
|
|
|
|
|
|
2009-08-15 01:04:14 +00:00
|
|
|
|
;; The pitem we start parsing with.
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(defconst js--initial-pitem
|
|
|
|
|
(make-js--pitem
|
|
|
|
|
:paren-depth most-negative-fixnum
|
2009-08-15 01:04:14 +00:00
|
|
|
|
:type 'toplevel))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
;;; User Customization
|
|
|
|
|
|
|
|
|
|
(defgroup js nil
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Customization variables for JavaScript mode."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
:tag "JavaScript"
|
|
|
|
|
:group 'languages)
|
|
|
|
|
|
|
|
|
|
(defcustom js-indent-level 4
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Number of spaces for each indentation step in `js-mode'."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
:type 'integer
|
2012-08-22 14:35:38 +09:00
|
|
|
|
:safe 'integerp
|
2009-08-14 23:02:38 +00:00
|
|
|
|
:group 'js)
|
|
|
|
|
|
|
|
|
|
(defcustom js-expr-indent-offset 0
|
2010-08-26 16:09:31 -04:00
|
|
|
|
"Number of additional spaces for indenting continued expressions.
|
2009-08-15 01:04:14 +00:00
|
|
|
|
The value must be no less than minus `js-indent-level'."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
:type 'integer
|
2012-08-22 14:35:38 +09:00
|
|
|
|
:safe 'integerp
|
2009-08-14 23:02:38 +00:00
|
|
|
|
:group 'js)
|
|
|
|
|
|
2010-08-26 16:09:31 -04:00
|
|
|
|
(defcustom js-paren-indent-offset 0
|
|
|
|
|
"Number of additional spaces for indenting expressions in parentheses.
|
|
|
|
|
The value must be no less than minus `js-indent-level'."
|
|
|
|
|
:type 'integer
|
2012-08-22 14:35:38 +09:00
|
|
|
|
:safe 'integerp
|
2010-08-26 16:09:31 -04:00
|
|
|
|
:group 'js
|
|
|
|
|
:version "24.1")
|
|
|
|
|
|
|
|
|
|
(defcustom js-square-indent-offset 0
|
|
|
|
|
"Number of additional spaces for indenting expressions in square braces.
|
|
|
|
|
The value must be no less than minus `js-indent-level'."
|
|
|
|
|
:type 'integer
|
2012-08-22 14:35:38 +09:00
|
|
|
|
:safe 'integerp
|
2010-08-26 16:09:31 -04:00
|
|
|
|
:group 'js
|
|
|
|
|
:version "24.1")
|
|
|
|
|
|
|
|
|
|
(defcustom js-curly-indent-offset 0
|
|
|
|
|
"Number of additional spaces for indenting expressions in curly braces.
|
|
|
|
|
The value must be no less than minus `js-indent-level'."
|
|
|
|
|
:type 'integer
|
2012-08-22 14:35:38 +09:00
|
|
|
|
:safe 'integerp
|
2010-08-26 16:09:31 -04:00
|
|
|
|
:group 'js
|
|
|
|
|
:version "24.1")
|
|
|
|
|
|
2013-12-08 18:08:45 +02:00
|
|
|
|
(defcustom js-switch-indent-offset 0
|
|
|
|
|
"Number of additional spaces for indenting the contents of a switch block.
|
|
|
|
|
The value must not be negative."
|
|
|
|
|
:type 'integer
|
|
|
|
|
:safe 'integerp
|
|
|
|
|
:group 'js
|
|
|
|
|
:version "24.4")
|
2010-03-28 16:41:37 -04:00
|
|
|
|
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(defcustom js-flat-functions nil
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Treat nested functions as top-level functions in `js-mode'.
|
|
|
|
|
This applies to function movement, marking, and so on."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
:type 'boolean
|
|
|
|
|
:group 'js)
|
|
|
|
|
|
2017-07-01 13:09:20 +02:00
|
|
|
|
(defcustom js-indent-align-list-continuation t
|
|
|
|
|
"Align continuation of non-empty ([{ lines in `js-mode'."
|
2017-12-12 23:21:24 -08:00
|
|
|
|
:version "26.1"
|
2017-07-01 13:09:20 +02:00
|
|
|
|
:type 'boolean
|
2019-02-09 11:50:05 -08:00
|
|
|
|
:safe 'booleanp
|
2017-07-01 13:09:20 +02:00
|
|
|
|
:group 'js)
|
|
|
|
|
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(defcustom js-comment-lineup-func #'c-lineup-C-comments
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Lineup function for `cc-mode-style', for C comments in `js-mode'."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
:type 'function
|
|
|
|
|
:group 'js)
|
|
|
|
|
|
|
|
|
|
(defcustom js-enabled-frameworks js--available-frameworks
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Frameworks recognized by `js-mode'.
|
|
|
|
|
To improve performance, you may turn off some frameworks you
|
|
|
|
|
seldom use, either globally or on a per-buffer basis."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
:type (cons 'set (mapcar (lambda (x)
|
|
|
|
|
(list 'const x))
|
|
|
|
|
js--available-frameworks))
|
|
|
|
|
:group 'js)
|
|
|
|
|
|
|
|
|
|
(defcustom js-js-switch-tabs
|
|
|
|
|
(and (memq system-type '(darwin)) t)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Whether `js-mode' should display tabs while selecting them.
|
|
|
|
|
This is useful only if the windowing system has a good mechanism
|
|
|
|
|
for preventing Firefox from stealing the keyboard focus."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
:type 'boolean
|
|
|
|
|
:group 'js)
|
|
|
|
|
|
|
|
|
|
(defcustom js-js-tmpdir
|
|
|
|
|
"~/.emacs.d/js/js"
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Temporary directory used by `js-mode' to communicate with Mozilla.
|
2010-06-22 00:04:20 -07:00
|
|
|
|
This directory must be readable and writable by both Mozilla and Emacs."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
:type 'directory
|
|
|
|
|
:group 'js)
|
|
|
|
|
|
|
|
|
|
(defcustom js-js-timeout 5
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Reply timeout for executing commands in Mozilla via `js-mode'.
|
|
|
|
|
The value is given in seconds. Increase this value if you are
|
|
|
|
|
getting timeout messages."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
:type 'integer
|
|
|
|
|
:group 'js)
|
|
|
|
|
|
2015-03-10 16:29:01 -07:00
|
|
|
|
(defcustom js-indent-first-init nil
|
|
|
|
|
"Non-nil means specially indent the first variable declaration's initializer.
|
|
|
|
|
Normally, the first declaration's initializer is unindented, and
|
2015-03-10 18:40:09 -04:00
|
|
|
|
subsequent declarations have their identifiers aligned with it:
|
2015-03-07 18:01:05 -08:00
|
|
|
|
|
|
|
|
|
var o = {
|
|
|
|
|
foo: 3
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var o = {
|
|
|
|
|
foo: 3
|
|
|
|
|
},
|
|
|
|
|
bar = 2;
|
|
|
|
|
|
2015-03-10 18:40:09 -04:00
|
|
|
|
If this option has the value t, indent the first declaration's
|
2015-03-10 16:29:01 -07:00
|
|
|
|
initializer by an additional level:
|
2015-03-07 18:01:05 -08:00
|
|
|
|
|
|
|
|
|
var o = {
|
|
|
|
|
foo: 3
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var o = {
|
|
|
|
|
foo: 3
|
|
|
|
|
},
|
|
|
|
|
bar = 2;
|
|
|
|
|
|
2015-03-10 18:40:09 -04:00
|
|
|
|
If this option has the value `dynamic', if there is only one declaration,
|
2015-03-10 16:29:01 -07:00
|
|
|
|
don't indent the first one's initializer; otherwise, indent it.
|
2015-03-07 18:01:05 -08:00
|
|
|
|
|
|
|
|
|
var o = {
|
|
|
|
|
foo: 3
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var o = {
|
|
|
|
|
foo: 3
|
|
|
|
|
},
|
|
|
|
|
bar = 2;"
|
2015-03-10 18:40:09 -04:00
|
|
|
|
:version "25.1"
|
|
|
|
|
:type '(choice (const nil) (const t) (const dynamic))
|
2015-03-07 18:01:05 -08:00
|
|
|
|
:safe 'symbolp
|
|
|
|
|
:group 'js)
|
|
|
|
|
|
2017-01-12 23:15:00 -07:00
|
|
|
|
(defcustom js-chain-indent nil
|
|
|
|
|
"Use \"chained\" indentation.
|
|
|
|
|
Chained indentation applies when the current line starts with \".\".
|
|
|
|
|
If the previous expression also contains a \".\" at the same level,
|
|
|
|
|
then the \".\"s will be lined up:
|
|
|
|
|
|
|
|
|
|
let x = svg.mumble()
|
|
|
|
|
.chained;
|
|
|
|
|
"
|
|
|
|
|
:version "26.1"
|
|
|
|
|
:type 'boolean
|
|
|
|
|
:safe 'booleanp
|
|
|
|
|
:group 'js)
|
|
|
|
|
|
2019-03-23 20:14:29 -07:00
|
|
|
|
(defcustom js-jsx-detect-syntax t
|
|
|
|
|
"When non-nil, automatically detect whether JavaScript uses JSX.
|
|
|
|
|
`js-jsx-syntax' (which see) may be made buffer-local and set to
|
|
|
|
|
t. The detection strategy can be customized by adding elements
|
|
|
|
|
to `js-jsx-regexps', which see."
|
|
|
|
|
:version "27.1"
|
|
|
|
|
:type 'boolean
|
|
|
|
|
:safe 'booleanp
|
|
|
|
|
:group 'js)
|
|
|
|
|
|
Refactor JSX indentation code to improve enclosing JSX discovery
Fix a number of bugs reported for JSX indentation (caused by poor JSX
detection):
- https://github.com/mooz/js2-mode/issues/140#issuecomment-166250016
- https://github.com/mooz/js2-mode/issues/490
- Bug#24896 / https://github.com/mooz/js2-mode/issues/389 (with
respect to comments)
- Bug#26001 /
https://github.com/mooz/js2-mode/issues/389#issuecomment-271869380
- https://github.com/mooz/js2-mode/issues/411 / Bug#27000 /
https://github.com/mooz/js2-mode/issues/451
Potentially manifest some new bugs (due to false positives with ‘<’
and ‘>’ and SGML detection). Slow down indentation a fair bit.
* list/progmodes/js.el (js-jsx-syntax, js--jsx-start-tag-re)
(js--looking-at-jsx-start-tag-p, js--looking-back-at-jsx-end-tag-p):
New variables and functions.
(js--jsx-find-before-tag, js--jsx-after-tag-re): Deleted.
(js--looking-at-operator-p): Don’t mistake a JSXOpeningElement for the
‘<’ operator.
(js--continued-expression-p): Don’t mistake a JSXClosingElement as a
fragment of a continued expression including the ‘>’ operator.
(js--as-sgml): Simplify. Probably needn’t bind forward-sexp-function
to nil (sgml-mode already does) and probably shouldn’t bind
parse-sexp-lookup-properties to nil either (see Bug#24896).
(js--outermost-enclosing-jsx-tag-pos): Find enclosing JSX more
accurately than js--jsx-find-before-tag. Use sgml-mode’s parsing
logic, rather than unreliable heuristics like paren-wrapping. This
implementation is much slower; the previous implementation was fast,
but at the expense of accuracy. To make up for all the grief we’ve
caused users, we will prefer accuracy over speed from now on. That
said, this can still probably be optimized a lot.
(js--jsx-indented-element-p): Rename to js--jsx-indentation, since it
doesn’t just return a boolean.
(js--jsx-indentation): Refactor js--jsx-indented-element-p to simplify
the implementation as the improved accuracy of other code allows (and
to repent for some awful stylistic choices I made earlier).
(js--expression-in-sgml-indent-line): Rename to
js--indent-line-in-jsx-expression, since it’s a private function and
we can give it a name that reads more like English.
(js--indent-line-in-jsx-expression): Restructure point adjustment
logic more like js-indent-line.
(js--indent-n+1th-jsx-line): New function to complement
js--indent-line-in-jsx-expression.
(js-jsx-indent-line): Refactor. Don’t bind js--continued-expression-p
to ignore any more; instead, rely on the improved accuracy of
js--continued-expression-p.
(js-jsx-mode): Set js-jsx-syntax to t. For now, this will be the flag
we use to determine whether ‘JSX is enabled.’ (Maybe later, we will
refactor the code to use this variable instead of requiring
js-jsx-mode to be enabled, thus rendering the mode obsolete.)
2019-02-09 20:06:29 -08:00
|
|
|
|
(defcustom js-jsx-syntax nil
|
|
|
|
|
"When non-nil, parse JavaScript with consideration for JSX syntax.
|
2019-03-23 20:14:29 -07:00
|
|
|
|
|
|
|
|
|
This enables proper font-locking and indentation of code using
|
|
|
|
|
Facebook’s “JSX” syntax extension for JavaScript, for use with
|
|
|
|
|
Facebook’s “React” library. Font-locking is like sgml-mode.
|
|
|
|
|
Indentation is also like sgml-mode, although some indentation
|
|
|
|
|
behavior may differ slightly to align more closely with the
|
|
|
|
|
conventions of the React developer community.
|
|
|
|
|
|
|
|
|
|
When `js-mode' is already enabled, you should call
|
|
|
|
|
`js-jsx-enable' to set this variable.
|
|
|
|
|
|
|
|
|
|
It is set to be buffer-local (and t) when in `js-jsx-mode'."
|
Refactor JSX indentation code to improve enclosing JSX discovery
Fix a number of bugs reported for JSX indentation (caused by poor JSX
detection):
- https://github.com/mooz/js2-mode/issues/140#issuecomment-166250016
- https://github.com/mooz/js2-mode/issues/490
- Bug#24896 / https://github.com/mooz/js2-mode/issues/389 (with
respect to comments)
- Bug#26001 /
https://github.com/mooz/js2-mode/issues/389#issuecomment-271869380
- https://github.com/mooz/js2-mode/issues/411 / Bug#27000 /
https://github.com/mooz/js2-mode/issues/451
Potentially manifest some new bugs (due to false positives with ‘<’
and ‘>’ and SGML detection). Slow down indentation a fair bit.
* list/progmodes/js.el (js-jsx-syntax, js--jsx-start-tag-re)
(js--looking-at-jsx-start-tag-p, js--looking-back-at-jsx-end-tag-p):
New variables and functions.
(js--jsx-find-before-tag, js--jsx-after-tag-re): Deleted.
(js--looking-at-operator-p): Don’t mistake a JSXOpeningElement for the
‘<’ operator.
(js--continued-expression-p): Don’t mistake a JSXClosingElement as a
fragment of a continued expression including the ‘>’ operator.
(js--as-sgml): Simplify. Probably needn’t bind forward-sexp-function
to nil (sgml-mode already does) and probably shouldn’t bind
parse-sexp-lookup-properties to nil either (see Bug#24896).
(js--outermost-enclosing-jsx-tag-pos): Find enclosing JSX more
accurately than js--jsx-find-before-tag. Use sgml-mode’s parsing
logic, rather than unreliable heuristics like paren-wrapping. This
implementation is much slower; the previous implementation was fast,
but at the expense of accuracy. To make up for all the grief we’ve
caused users, we will prefer accuracy over speed from now on. That
said, this can still probably be optimized a lot.
(js--jsx-indented-element-p): Rename to js--jsx-indentation, since it
doesn’t just return a boolean.
(js--jsx-indentation): Refactor js--jsx-indented-element-p to simplify
the implementation as the improved accuracy of other code allows (and
to repent for some awful stylistic choices I made earlier).
(js--expression-in-sgml-indent-line): Rename to
js--indent-line-in-jsx-expression, since it’s a private function and
we can give it a name that reads more like English.
(js--indent-line-in-jsx-expression): Restructure point adjustment
logic more like js-indent-line.
(js--indent-n+1th-jsx-line): New function to complement
js--indent-line-in-jsx-expression.
(js-jsx-indent-line): Refactor. Don’t bind js--continued-expression-p
to ignore any more; instead, rely on the improved accuracy of
js--continued-expression-p.
(js-jsx-mode): Set js-jsx-syntax to t. For now, this will be the flag
we use to determine whether ‘JSX is enabled.’ (Maybe later, we will
refactor the code to use this variable instead of requiring
js-jsx-mode to be enabled, thus rendering the mode obsolete.)
2019-02-09 20:06:29 -08:00
|
|
|
|
:version "27.1"
|
|
|
|
|
:type 'boolean
|
|
|
|
|
:safe 'booleanp
|
|
|
|
|
:group 'js)
|
|
|
|
|
|
Indent JSX as parsed in a JS context
Fixes the following issues (and re-fixes indentation issues initially
fixed but later re-broken by previous commits in the process of adding
comprehensive JSX support):
- https://github.com/mooz/js2-mode/issues/389#issuecomment-390766873
- https://github.com/mooz/js2-mode/issues/482
- Bug#32158
- https://github.com/mooz/js2-mode/issues/462
Previously, we delegated to sgml-mode functions for JSX indentation.
However, there were some problems with this approach:
- sgml-mode does not anticipate tags inside attributes when indenting,
which compromises JSX indentation inside JSXExpressionContainers
inside JSXAttributes.
- In previous iterations to provide comprehensive JSX support, it
proved tedious to disambiguate “<” and “>” as JS inequality
operators and arrow functions from opening and closing angle
brackets as part of SGML tags. That code evolved into a more
complete JSX parsing implementation for syntax-propertize rules for
font-locking, discarding the superfluous “<”/“>” disambiguation in
anticipation of using the improved JSX analysis for indentation.
- Using sgml-mode functions, we controlled JSX indentation using SGML
variables. However, JSX is a different thing than SGML; referencing
SGML in JS was a leaky abstraction.
To resolve these issues, use the text properties added by the JSX
syntax-propertize code to determine the boundaries of various aspects
of JSX syntax, and reimplement the sgml-mode indentation code in
js-mode with better respect to JSX indentation conventions.
* lisp/progmodes/js.el (js-jsx-attribute-offset): New variable to
provide a way for users to still control JSX attribute offsets as they
could with sgml-attribute-offset before. The value of this feature is
dubious IMO, but it’s trivial to keep it, so let’s do it just in case.
(js-jsx--goto-outermost-enclosing-curly): New function.
(js-jsx--enclosing-tag-pos): Refactor to be unbounded by curlies, so
this function can be used to find JSXExpressionContainers within JSX.
Fix bug where an enclosing JSXElement couldn’t be found when point was
at the start of its JSXClosingElement. Return the JSXClosingElement’s
position as well, so the JSXClosingElement can be indentified when
indenting and be indented like the matching JSXOpeningElement.
(js-jsx--at-enclosing-tag-child-p): js-jsx--enclosing-tag-pos now
returns a list rather than a cons, so retrieve the JSXOpeningElement’s
end position from a list.
(js-jsx--context, js-jsx--indenting): New function and variable.
(js-jsx--indentation): New function replacing the prior
js-jsx--indent* functions and js-jsx-indent-line’s implementation.
Use the JSX parsing performed in a JS context to more accurately
calculate JSX indentation than by delegating to sgml-mode functions.
(js--proper-indentation): Use js-jsx--indentation as yet another type
of indentation.
(js-jsx--as-sgml, js-jsx--outermost-enclosing-tag-pos)
(js-jsx--indentation-type, js-jsx--indent-line-in-expression)
(js-jsx--indent-n+1th-line): Remove obsolete functions.
(js-jsx-indent-line): Refactor nearly-obsolete function to behave the
same as it usually would before these changes, without respect to the
binding of js-jsx-syntax.
(js-jsx-mode): Remove obsolete documentation about the use of SGML
variables to control indentation, and don’t bind indent-line-function
any more, because it is no longer necessary given the new
implementation of js-jsx-indent-line.
2019-03-23 14:22:35 -07:00
|
|
|
|
(defcustom js-jsx-attribute-offset 0
|
|
|
|
|
"Specifies a delta for JSXAttribute indentation.
|
|
|
|
|
|
|
|
|
|
Let `js-indent-level' be 2. When this variable is also set to 0,
|
|
|
|
|
JSXAttribute indentation looks like this:
|
|
|
|
|
|
|
|
|
|
<element
|
|
|
|
|
attribute=\"value\">
|
|
|
|
|
</element>
|
|
|
|
|
|
|
|
|
|
Alternatively, when this variable is also set to 2, JSXAttribute
|
|
|
|
|
indentation looks like this:
|
|
|
|
|
|
|
|
|
|
<element
|
|
|
|
|
attribute=\"value\">
|
|
|
|
|
</element>
|
|
|
|
|
|
|
|
|
|
This variable is like `sgml-attribute-offset'."
|
|
|
|
|
:version "27.1"
|
|
|
|
|
:type 'integer
|
|
|
|
|
:safe 'integerp
|
|
|
|
|
:group 'js)
|
|
|
|
|
|
2009-08-14 23:02:38 +00:00
|
|
|
|
;;; KeyMap
|
|
|
|
|
|
|
|
|
|
(defvar js-mode-map
|
|
|
|
|
(let ((keymap (make-sparse-keymap)))
|
|
|
|
|
(define-key keymap [(control ?c) (meta ?:)] #'js-eval)
|
|
|
|
|
(define-key keymap [(control ?c) (control ?j)] #'js-set-js-context)
|
|
|
|
|
(define-key keymap [(control meta ?x)] #'js-eval-defun)
|
|
|
|
|
(define-key keymap [(meta ?.)] #'js-find-symbol)
|
2017-01-29 10:39:55 +02:00
|
|
|
|
(easy-menu-define nil keymap "JavaScript Menu"
|
|
|
|
|
'("JavaScript"
|
2010-06-22 00:04:20 -07:00
|
|
|
|
["Select New Mozilla Context..." js-set-js-context
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(fboundp #'inferior-moz-process)]
|
2010-06-22 00:04:20 -07:00
|
|
|
|
["Evaluate Expression in Mozilla Context..." js-eval
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(fboundp #'inferior-moz-process)]
|
2010-06-22 00:04:20 -07:00
|
|
|
|
["Send Current Function to Mozilla..." js-eval-defun
|
2009-08-15 01:04:14 +00:00
|
|
|
|
(fboundp #'inferior-moz-process)]))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
keymap)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Keymap for `js-mode'.")
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
;;; Syntax table and parsing
|
|
|
|
|
|
|
|
|
|
(defvar js-mode-syntax-table
|
|
|
|
|
(let ((table (make-syntax-table)))
|
|
|
|
|
(c-populate-syntax-table table)
|
|
|
|
|
(modify-syntax-entry ?$ "_" table)
|
2015-03-05 04:33:36 +02:00
|
|
|
|
(modify-syntax-entry ?` "\"" table)
|
2009-08-14 23:02:38 +00:00
|
|
|
|
table)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Syntax table for `js-mode'.")
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defvar js--quick-match-re nil
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Autogenerated regexp used by `js-mode' to match buffer constructs.")
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defvar js--quick-match-re-func nil
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Autogenerated regexp used by `js-mode' to match constructs and functions.")
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(make-variable-buffer-local 'js--quick-match-re)
|
|
|
|
|
(make-variable-buffer-local 'js--quick-match-re-func)
|
|
|
|
|
|
|
|
|
|
(defvar js--cache-end 1
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Last valid buffer position for the `js-mode' function cache.")
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(make-variable-buffer-local 'js--cache-end)
|
|
|
|
|
|
|
|
|
|
(defvar js--last-parse-pos nil
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Latest parse position reached by `js--ensure-cache'.")
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(make-variable-buffer-local 'js--last-parse-pos)
|
|
|
|
|
|
|
|
|
|
(defvar js--state-at-last-parse-pos nil
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Parse state at `js--last-parse-pos'.")
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(make-variable-buffer-local 'js--state-at-last-parse-pos)
|
|
|
|
|
|
|
|
|
|
(defun js--maybe-join (prefix separator suffix &rest list)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Helper function for `js--update-quick-match-re'.
|
|
|
|
|
If LIST contains any element that is not nil, return its non-nil
|
|
|
|
|
elements, separated by SEPARATOR, prefixed by PREFIX, and ended
|
* international/ucs-normalize.el (ucs-normalize-sort, quick-check-list):
Fix typos in docstrings.
* progmodes/js.el (js--macro-decl-re): Doc fix.
(js--plain-method-re, js--split-name): Refloc docstring.
(js--class-styles, js--make-merged-item, js--splice-into-items):
Fix typos in docstrings; reflow docstrings.
(js--maybe-join, js--function-prologue-beginning, js--flush-caches)
(js--variable-decl-matcher, js--inside-pitem-p)
(js--parse-state-at-point, js--get-all-known-symbols)
(js--symbol-history, js-find-symbol, js--js-references)
(js--moz-interactor, js--js-encode-value, js--read-tab):
Fix typos in docstrings.
2009-08-28 18:22:30 +00:00
|
|
|
|
with SUFFIX as with `concat'. Otherwise, if LIST is empty, return
|
|
|
|
|
nil. If any element in LIST is itself a list, flatten that
|
2009-08-14 23:02:38 +00:00
|
|
|
|
element."
|
New function flatten-tree
Co-authored-by: Basil L. Contovounesios <contovob@tcd.ie>
* doc/lispref/lists.texi: Document `flatten-tree'.
* lisp/progmodes/js.el (js--maybe-join):
* lisp/printing.el (pr-switches):
* lisp/lpr.el (lpr-print-region):
* lisp/gnus/nnimap.el (nnimap-find-wanted-parts):
* lisp/gnus/message.el (message-talkative-question):
* lisp/gnus/gnus-sum.el (gnus-remove-thread)
(gnus-thread-highest-number, gnus-thread-latest-date):
* lisp/eshell/esh-util.el (eshell-flatten-and-stringify):
* lisp/eshell/esh-opt.el (eshell-eval-using-options):
* lisp/eshell/esh-ext.el (eshell-external-command):
* lisp/eshell/em-xtra.el (eshell/expr):
* lisp/eshell/em-unix.el (eshell/rm, eshell-mvcpln-template)
(eshell/cat, eshell/make, eshell-poor-mans-grep, eshell-grep)
(eshell/du, eshell/time, eshell/diff, eshell/locate):
* lisp/eshell/em-tramp.el (eshell/su, eshell/sudo):
* lisp/eshell/em-term.el (eshell-exec-visual):
* lisp/eshell/em-dirs.el (eshell-dirs-substitute-cd, eshell/cd):
* lisp/eshell/em-basic.el (eshell/printnl):
Use new flatten-tree.
* lisp/progmodes/js.el (js--flatten-list):
* lisp/lpr.el (lpr-flatten-list):
* lisp/gnus/message.el (message-flatten-list):
* lisp/eshell/esh-util.el (eshell-flatten-list):
Obsolete in favor of Emacs-wide `flatten-tree'.
* lisp/subr.el (flatten-list): Alias to `flatten-tree' for
discoverability.
* lisp/subr.el (flatten-tree): New defun.
* test/lisp/subr-tests.el (subr-tests-flatten-tree): New test.
2018-12-17 12:15:09 +01:00
|
|
|
|
(setq list (flatten-tree list))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(when list
|
|
|
|
|
(concat prefix (mapconcat #'identity list separator) suffix)))
|
|
|
|
|
|
|
|
|
|
(defun js--update-quick-match-re ()
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Internal function used by `js-mode' for caching buffer constructs.
|
|
|
|
|
This updates `js--quick-match-re', based on the current set of
|
|
|
|
|
enabled frameworks."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(setq js--quick-match-re
|
|
|
|
|
(js--maybe-join
|
|
|
|
|
"^[ \t]*\\(?:" "\\|" "\\)"
|
|
|
|
|
|
|
|
|
|
;; #define mumble
|
|
|
|
|
"#define[ \t]+[a-zA-Z_]"
|
|
|
|
|
|
|
|
|
|
(when (memq 'extjs js-enabled-frameworks)
|
|
|
|
|
"Ext\\.extend")
|
|
|
|
|
|
|
|
|
|
(when (memq 'prototype js-enabled-frameworks)
|
|
|
|
|
"Object\\.extend")
|
|
|
|
|
|
|
|
|
|
;; var mumble = THING (
|
|
|
|
|
(js--maybe-join
|
|
|
|
|
"\\(?:var[ \t]+\\)?[a-zA-Z_$0-9.]+[ \t]*=[ \t]*\\(?:"
|
|
|
|
|
"\\|"
|
2015-09-17 16:08:20 -07:00
|
|
|
|
"\\)[ \t]*("
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(when (memq 'prototype js-enabled-frameworks)
|
|
|
|
|
"Class\\.create")
|
|
|
|
|
|
|
|
|
|
(when (memq 'extjs js-enabled-frameworks)
|
|
|
|
|
"Ext\\.extend")
|
|
|
|
|
|
|
|
|
|
(when (memq 'merrillpress js-enabled-frameworks)
|
|
|
|
|
"[a-zA-Z_$0-9]+\\.extend\\(?:Final\\)?"))
|
|
|
|
|
|
|
|
|
|
(when (memq 'dojo js-enabled-frameworks)
|
2015-09-17 16:08:20 -07:00
|
|
|
|
"dojo\\.declare[ \t]*(")
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(when (memq 'mochikit js-enabled-frameworks)
|
2015-09-17 16:08:20 -07:00
|
|
|
|
"MochiKit\\.Base\\.update[ \t]*(")
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
;; mumble.prototypeTHING
|
|
|
|
|
(js--maybe-join
|
|
|
|
|
"[a-zA-Z_$0-9.]+\\.prototype\\(?:" "\\|" "\\)"
|
|
|
|
|
|
|
|
|
|
(when (memq 'javascript js-enabled-frameworks)
|
|
|
|
|
'( ;; foo.prototype.bar = function(
|
2015-09-17 16:08:20 -07:00
|
|
|
|
"\\.[a-zA-Z_$0-9]+[ \t]*=[ \t]*function[ \t]*("
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
;; mumble.prototype = {
|
|
|
|
|
"[ \t]*=[ \t]*{")))))
|
|
|
|
|
|
|
|
|
|
(setq js--quick-match-re-func
|
|
|
|
|
(concat "function\\|" js--quick-match-re)))
|
|
|
|
|
|
|
|
|
|
(defun js--forward-text-property (propname)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Move over the next value of PROPNAME in the buffer.
|
|
|
|
|
If found, return that value and leave point after the character
|
|
|
|
|
having that value; otherwise, return nil and leave point at EOB."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(let ((next-value (get-text-property (point) propname)))
|
|
|
|
|
(if next-value
|
|
|
|
|
(forward-char)
|
|
|
|
|
|
|
|
|
|
(goto-char (next-single-property-change
|
|
|
|
|
(point) propname nil (point-max)))
|
|
|
|
|
(unless (eobp)
|
|
|
|
|
(setq next-value (get-text-property (point) propname))
|
|
|
|
|
(forward-char)))
|
|
|
|
|
|
|
|
|
|
next-value))
|
|
|
|
|
|
|
|
|
|
(defun js--backward-text-property (propname)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Move over the previous value of PROPNAME in the buffer.
|
|
|
|
|
If found, return that value and leave point just before the
|
|
|
|
|
character that has that value, otherwise return nil and leave
|
|
|
|
|
point at BOB."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(unless (bobp)
|
|
|
|
|
(let ((prev-value (get-text-property (1- (point)) propname)))
|
|
|
|
|
(if prev-value
|
|
|
|
|
(backward-char)
|
|
|
|
|
|
|
|
|
|
(goto-char (previous-single-property-change
|
|
|
|
|
(point) propname nil (point-min)))
|
|
|
|
|
|
|
|
|
|
(unless (bobp)
|
|
|
|
|
(backward-char)
|
|
|
|
|
(setq prev-value (get-text-property (point) propname))))
|
|
|
|
|
|
|
|
|
|
prev-value)))
|
|
|
|
|
|
|
|
|
|
(defsubst js--forward-pstate ()
|
|
|
|
|
(js--forward-text-property 'js--pstate))
|
|
|
|
|
|
|
|
|
|
(defsubst js--backward-pstate ()
|
|
|
|
|
(js--backward-text-property 'js--pstate))
|
|
|
|
|
|
|
|
|
|
(defun js--pitem-goto-h-end (pitem)
|
|
|
|
|
(goto-char (js--pitem-h-begin pitem))
|
|
|
|
|
(js--forward-pstate))
|
|
|
|
|
|
|
|
|
|
(defun js--re-search-forward-inner (regexp &optional bound count)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Helper function for `js--re-search-forward'."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(let ((parse)
|
|
|
|
|
str-terminator
|
|
|
|
|
(orig-macro-end (save-excursion
|
|
|
|
|
(when (js--beginning-of-macro)
|
|
|
|
|
(c-end-of-macro)
|
|
|
|
|
(point)))))
|
|
|
|
|
(while (> count 0)
|
|
|
|
|
(re-search-forward regexp bound)
|
|
|
|
|
(setq parse (syntax-ppss))
|
|
|
|
|
(cond ((setq str-terminator (nth 3 parse))
|
|
|
|
|
(when (eq str-terminator t)
|
|
|
|
|
(setq str-terminator ?/))
|
|
|
|
|
(re-search-forward
|
|
|
|
|
(concat "\\([^\\]\\|^\\)" (string str-terminator))
|
Replace end-of-line, save-excursion etc with point-at-eol, point-at-bol.
* lisp/mh-e/mh-seq.el (mh-read-msg-list): Use point-at-eol.
* lisp/gnus/gnus-bookmark.el (gnus-bookmark-bmenu-show-infos)
(gnus-bookmark-kill-line): Use point-at-eol.
* lisp/cedet/ede/proj-elisp.el (ede-proj-flush-autoconf): Use point-at-bol.
* lisp/emacs-lisp/chart.el (chart-zap-chars):
* lisp/play/decipher.el (decipher-set-map):
* lisp/progmodes/ada-mode.el (ada-get-current-indent)
(ada-search-ignore-string-comment, ada-tab-hard, ada-untab-hard):
* lisp/progmodes/ada-prj.el (ada-prj-load-from-file, ada-prj-display-help):
* lisp/progmodes/ada-xref.el (ada-initialize-runtime-library)
(ada-get-all-references):
* lisp/progmodes/cperl-mode.el (cperl-electric-paren)
(cperl-electric-rparen, cperl-electric-keyword, cperl-electric-else)
(cperl-linefeed, cperl-sniff-for-indent, cperl-to-comment-or-eol)
(cperl-find-pods-heres, cperl-indent-exp, cperl-fix-line-spacing)
(cperl-word-at-point-hard):
* lisp/progmodes/idlw-shell.el (idlwave-shell-move-or-history)
(idlwave-shell-filename-string, idlwave-shell-batch-command)
(idlwave-shell-display-line):
* lisp/progmodes/idlwave.el (idlwave-show-begin, idlwave-fill-paragraph)
(idlwave-calc-hanging-indent, idlwave-auto-fill, idlwave-template):
* lisp/progmodes/js.el (js--re-search-forward-inner)
(js--re-search-backward-inner):
* lisp/progmodes/vhdl-mode.el (vhdl-align-region-1, vhdl-align-region-2)
(vhdl-fix-clause, vhdl-compose-configuration-architecture):
* lisp/progmodes/ruby-mode.el (ruby-parse-partial, eval-when-compile):
* lisp/textmodes/flyspell.el (flyspell-process-localwords):
* lisp/textmodes/ispell.el (ispell-buffer-local-parsing)
(ispell-buffer-local-dict, ispell-buffer-local-words):
Use point-at-bol and point-at-eol.
2010-11-06 18:36:33 -07:00
|
|
|
|
(point-at-eol) t))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
((nth 7 parse)
|
|
|
|
|
(forward-line))
|
|
|
|
|
((or (nth 4 parse)
|
|
|
|
|
(and (eq (char-before) ?\/) (eq (char-after) ?\*)))
|
|
|
|
|
(re-search-forward "\\*/"))
|
|
|
|
|
((and (not (and orig-macro-end
|
|
|
|
|
(<= (point) orig-macro-end)))
|
|
|
|
|
(js--beginning-of-macro))
|
|
|
|
|
(c-end-of-macro))
|
|
|
|
|
(t
|
|
|
|
|
(setq count (1- count))))))
|
|
|
|
|
(point))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defun js--re-search-forward (regexp &optional bound noerror count)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Search forward, ignoring strings, cpp macros, and comments.
|
|
|
|
|
This function invokes `re-search-forward', but treats the buffer
|
|
|
|
|
as if strings, cpp macros, and comments have been removed.
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
2009-08-15 01:04:14 +00:00
|
|
|
|
If invoked while inside a macro, it treats the contents of the
|
|
|
|
|
macro as normal text."
|
2010-09-08 18:21:23 +02:00
|
|
|
|
(unless count (setq count 1))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(let ((saved-point (point))
|
2010-09-08 18:21:23 +02:00
|
|
|
|
(search-fun
|
|
|
|
|
(cond ((< count 0) (setq count (- count))
|
|
|
|
|
#'js--re-search-backward-inner)
|
|
|
|
|
((> count 0) #'js--re-search-forward-inner)
|
|
|
|
|
(t #'ignore))))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(condition-case err
|
2010-09-08 18:21:23 +02:00
|
|
|
|
(funcall search-fun regexp bound count)
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(search-failed
|
|
|
|
|
(goto-char saved-point)
|
|
|
|
|
(unless noerror
|
2010-09-08 18:21:23 +02:00
|
|
|
|
(signal (car err) (cdr err)))))))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defun js--re-search-backward-inner (regexp &optional bound count)
|
|
|
|
|
"Auxiliary function for `js--re-search-backward'."
|
|
|
|
|
(let ((parse)
|
|
|
|
|
(orig-macro-start
|
|
|
|
|
(save-excursion
|
|
|
|
|
(and (js--beginning-of-macro)
|
|
|
|
|
(point)))))
|
|
|
|
|
(while (> count 0)
|
|
|
|
|
(re-search-backward regexp bound)
|
|
|
|
|
(when (and (> (point) (point-min))
|
|
|
|
|
(save-excursion (backward-char) (looking-at "/[/*]")))
|
|
|
|
|
(forward-char))
|
|
|
|
|
(setq parse (syntax-ppss))
|
2019-02-01 03:01:39 +03:00
|
|
|
|
(cond ((nth 8 parse)
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(goto-char (nth 8 parse)))
|
|
|
|
|
((or (nth 4 parse)
|
|
|
|
|
(and (eq (char-before) ?/) (eq (char-after) ?*)))
|
|
|
|
|
(re-search-backward "/\\*"))
|
|
|
|
|
((and (not (and orig-macro-start
|
|
|
|
|
(>= (point) orig-macro-start)))
|
|
|
|
|
(js--beginning-of-macro)))
|
|
|
|
|
(t
|
|
|
|
|
(setq count (1- count))))))
|
|
|
|
|
(point))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defun js--re-search-backward (regexp &optional bound noerror count)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Search backward, ignoring strings, preprocessor macros, and comments.
|
|
|
|
|
|
|
|
|
|
This function invokes `re-search-backward' but treats the buffer
|
|
|
|
|
as if strings, preprocessor macros, and comments have been
|
|
|
|
|
removed.
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
2009-08-15 01:04:14 +00:00
|
|
|
|
If invoked while inside a macro, treat the macro as normal text."
|
2010-09-08 18:21:23 +02:00
|
|
|
|
(js--re-search-forward regexp bound noerror (if count (- count) -1)))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defun js--forward-expression ()
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Move forward over a whole JavaScript expression.
|
|
|
|
|
This function doesn't move over expressions continued across
|
|
|
|
|
lines."
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cl-loop
|
2009-08-14 23:02:38 +00:00
|
|
|
|
;; non-continued case; simplistic, but good enough?
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
do (cl-loop until (or (eolp)
|
|
|
|
|
(progn
|
|
|
|
|
(forward-comment most-positive-fixnum)
|
|
|
|
|
(memq (char-after) '(?\, ?\; ?\] ?\) ?\}))))
|
|
|
|
|
do (forward-sexp))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
while (and (eq (char-after) ?\n)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(forward-char)
|
|
|
|
|
(js--continued-expression-p)))))
|
|
|
|
|
|
|
|
|
|
(defun js--forward-function-decl ()
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Move forward over a JavaScript function declaration.
|
2015-11-17 15:28:50 -08:00
|
|
|
|
This puts point at the `function' keyword.
|
2009-08-15 01:04:14 +00:00
|
|
|
|
|
|
|
|
|
If this is a syntactically-correct non-expression function,
|
|
|
|
|
return the name of the function, or t if the name could not be
|
|
|
|
|
determined. Otherwise, return nil."
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cl-assert (looking-at "\\_<function\\_>"))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(let ((name t))
|
Fix problems caused by new implementation of sub-word mode
* lisp/subr.el (forward-word-strictly, backward-word-strictly):
New functions.
(word-move-empty-char-table): New variable.
* etc/NEWS: Mention 'forward-word-strictly' and
'backward-word-strictly'.
* doc/lispref/positions.texi (Word Motion): Document
'find-word-boundary-function-table', 'forward-word-strictly', and
'backward-word-strictly'. (Bug#22560)
* src/syntax.c (syms_of_syntax)
<find-word-boundary-function-table>: Doc fix.
* lisp/wdired.el (wdired-xcase-word):
* lisp/textmodes/texnfo-upd.el (texinfo-copy-node-name)
(texinfo-copy-section-title, texinfo-start-menu-description)
(texinfo-copy-menu-title, texinfo-specific-section-type)
(texinfo-insert-node-lines, texinfo-copy-next-section-title):
* lisp/textmodes/texinfo.el (texinfo-clone-environment)
(texinfo-insert-@end):
* lisp/textmodes/texinfmt.el (texinfo-format-scan)
(texinfo-anchor, texinfo-multitable-widths)
(texinfo-multitable-item):
* lisp/textmodes/tex-mode.el (latex-env-before-change):
* lisp/textmodes/flyspell.el (texinfo-mode-flyspell-verify):
* lisp/skeleton.el (skeleton-insert):
* lisp/simple.el (count-words):
* lisp/progmodes/vhdl-mode.el (vhdl-beginning-of-libunit)
(vhdl-beginning-of-defun, vhdl-beginning-of-statement-1)
(vhdl-update-sensitivity-list, vhdl-template-block)
(vhdl-template-break, vhdl-template-case, vhdl-template-default)
(vhdl-template-default-indent, vhdl-template-for-loop)
(vhdl-template-if-then-use, vhdl-template-bare-loop)
(vhdl-template-nature, vhdl-template-procedural)
(vhdl-template-process, vhdl-template-selected-signal-asst)
(vhdl-template-type, vhdl-template-variable)
(vhdl-template-while-loop, vhdl-beginning-of-block)
(vhdl-hooked-abbrev, vhdl-port-copy, vhdl-hs-forward-sexp-func):
* lisp/progmodes/verilog-mode.el (verilog-backward-sexp)
(verilog-forward-sexp, verilog-beg-of-statement)
(verilog-set-auto-endcomments, verilog-backward-token)
(verilog-do-indent):
* lisp/progmodes/vera-mode.el (vera-guess-basic-syntax)
(vera-indent-block-closing):
* lisp/progmodes/simula.el (simula-context)
(simula-backward-up-level, simula-forward-down-level)
(simula-previous-statement, simula-next-statement)
(simula-skip-comment-backward, simula-calculate-indent)
(simula-find-if, simula-electric-keyword):
* lisp/progmodes/sh-script.el (sh-smie--rc-newline-semi-p):
* lisp/progmodes/ruby-mode.el (ruby-smie--redundant-do-p)
(ruby-smie--forward-token, ruby-smie--backward-token)
(ruby-singleton-class-p, ruby-calculate-indent)
(ruby-forward-sexp, ruby-backward-sexp):
* lisp/progmodes/ps-mode.el (ps-run-goto-error):
* lisp/progmodes/perl-mode.el (perl-syntax-propertize-function)
(perl-syntax-propertize-special-constructs)
(perl-backward-to-start-of-continued-exp):
* lisp/progmodes/pascal.el (pascal-indent-declaration):
* lisp/progmodes/octave.el (octave-function-file-p):
* lisp/progmodes/mantemp.el (mantemp-insert-cxx-syntax):
* lisp/progmodes/js.el (js--forward-function-decl):
* lisp/progmodes/idlwave.el (idlwave-show-begin-check)
(idlwave-beginning-of-block, idlwave-end-of-block)
(idlwave-block-jump-out, idlwave-determine-class):
* lisp/progmodes/icon.el (icon-is-continuation-line)
(icon-backward-to-start-of-continued-exp, end-of-icon-defun):
* lisp/progmodes/hideif.el (hide-ifdef-define):
* lisp/progmodes/f90.el (f90-change-keywords):
* lisp/progmodes/cperl-mode.el (cperl-electric-pod)
(cperl-linefeed, cperl-electric-terminator)
(cperl-find-pods-heres, cperl-fix-line-spacing)
(cperl-invert-if-unless):
* lisp/progmodes/cc-engine.el (c-forward-<>-arglist-recur):
* lisp/progmodes/cc-align.el (c-lineup-java-inher):
* lisp/progmodes/ada-mode.el (ada-compile-goto-error)
(ada-adjust-case-skeleton, ada-create-case-exception)
(ada-create-case-exception-substring)
(ada-case-read-exceptions-from-file, ada-after-keyword-p)
(ada-scan-paramlist, ada-get-current-indent, ada-get-indent-end)
(ada-get-indent-if, ada-get-indent-block-start)
(ada-get-indent-loop, ada-get-indent-type)
(ada-search-prev-end-stmt, ada-check-defun-name)
(ada-goto-decl-start, ada-goto-matching-start)
(ada-goto-matching-end, ada-looking-at-semi-or)
(ada-looking-at-semi-private, ada-in-paramlist-p)
(ada-search-ignore-complex-boolean, ada-move-to-start)
(ada-move-to-end, ada-which-function, ada-gen-treat-proc):
* lisp/net/quickurl.el (quickurl-grab-url):
* lisp/mail/sendmail.el (mail-do-fcc):
* lisp/mail/rmail.el (rmail-resend):
* lisp/mail/mailabbrev.el (mail-abbrev-complete-alias):
* lisp/mail/mail-extr.el (mail-extract-address-components):
* lisp/json.el (json-read-keyword):
* lisp/files.el (insert-directory):
* lisp/emacs-lisp/checkdoc.el (checkdoc-this-string-valid-engine):
* lisp/completion.el (symbol-under-point, symbol-before-point)
(symbol-before-point-for-complete, next-cdabbrev)
(add-completions-from-c-buffer):
* lisp/cedet/semantic/texi.el (semantic-up-context)
(semantic-beginning-of-context):
* lisp/cedet/semantic/bovine/el.el (semantic-get-local-variables):
use 'forward-word-strictly' and 'backward-word-strictly' instead
of 'forward-word' and 'backward-word'.
2016-02-05 23:54:21 +02:00
|
|
|
|
(forward-word-strictly)
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(forward-comment most-positive-fixnum)
|
2015-01-09 10:25:50 -08:00
|
|
|
|
(when (eq (char-after) ?*)
|
|
|
|
|
(forward-char)
|
|
|
|
|
(forward-comment most-positive-fixnum))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(when (looking-at js--name-re)
|
|
|
|
|
(setq name (match-string-no-properties 0))
|
|
|
|
|
(goto-char (match-end 0)))
|
|
|
|
|
(forward-comment most-positive-fixnum)
|
|
|
|
|
(and (eq (char-after) ?\( )
|
|
|
|
|
(ignore-errors (forward-list) t)
|
|
|
|
|
(progn (forward-comment most-positive-fixnum)
|
|
|
|
|
(and (eq (char-after) ?{)
|
|
|
|
|
name)))))
|
|
|
|
|
|
|
|
|
|
(defun js--function-prologue-beginning (&optional pos)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Return the start of the JavaScript function prologue containing POS.
|
|
|
|
|
A function prologue is everything from start of the definition up
|
* international/ucs-normalize.el (ucs-normalize-sort, quick-check-list):
Fix typos in docstrings.
* progmodes/js.el (js--macro-decl-re): Doc fix.
(js--plain-method-re, js--split-name): Refloc docstring.
(js--class-styles, js--make-merged-item, js--splice-into-items):
Fix typos in docstrings; reflow docstrings.
(js--maybe-join, js--function-prologue-beginning, js--flush-caches)
(js--variable-decl-matcher, js--inside-pitem-p)
(js--parse-state-at-point, js--get-all-known-symbols)
(js--symbol-history, js-find-symbol, js--js-references)
(js--moz-interactor, js--js-encode-value, js--read-tab):
Fix typos in docstrings.
2009-08-28 18:22:30 +00:00
|
|
|
|
to and including the opening brace. POS defaults to point.
|
2009-08-15 01:04:14 +00:00
|
|
|
|
If POS is not in a function prologue, return nil."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(let (prologue-begin)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(if pos
|
|
|
|
|
(goto-char pos)
|
|
|
|
|
(setq pos (point)))
|
|
|
|
|
|
|
|
|
|
(when (save-excursion
|
|
|
|
|
(forward-line 0)
|
|
|
|
|
(or (looking-at js--function-heading-2-re)
|
|
|
|
|
(looking-at js--function-heading-3-re)))
|
|
|
|
|
|
|
|
|
|
(setq prologue-begin (match-beginning 1))
|
|
|
|
|
(when (<= prologue-begin pos)
|
|
|
|
|
(goto-char (match-end 0))))
|
|
|
|
|
|
|
|
|
|
(skip-syntax-backward "w_")
|
|
|
|
|
(and (or (looking-at "\\_<function\\_>")
|
|
|
|
|
(js--re-search-backward "\\_<function\\_>" nil t))
|
|
|
|
|
|
|
|
|
|
(save-match-data (goto-char (match-beginning 0))
|
|
|
|
|
(js--forward-function-decl))
|
|
|
|
|
|
|
|
|
|
(<= pos (point))
|
|
|
|
|
(or prologue-begin (match-beginning 0))))))
|
|
|
|
|
|
|
|
|
|
(defun js--beginning-of-defun-raw ()
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Helper function for `js-beginning-of-defun'.
|
|
|
|
|
Go to previous defun-beginning and return the parse state for it,
|
|
|
|
|
or nil if we went all the way back to bob and don't find
|
|
|
|
|
anything."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(js--ensure-cache)
|
|
|
|
|
(let (pstate)
|
|
|
|
|
(while (and (setq pstate (js--backward-pstate))
|
|
|
|
|
(not (eq 'function (js--pitem-type (car pstate))))))
|
|
|
|
|
(and (not (bobp)) pstate)))
|
|
|
|
|
|
|
|
|
|
(defun js--pstate-is-toplevel-defun (pstate)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Helper function for `js--beginning-of-defun-nested'.
|
|
|
|
|
If PSTATE represents a non-empty top-level defun, return the
|
|
|
|
|
top-most pitem. Otherwise, return nil."
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cl-loop for pitem in pstate
|
|
|
|
|
with func-depth = 0
|
|
|
|
|
with func-pitem
|
|
|
|
|
if (eq 'function (js--pitem-type pitem))
|
|
|
|
|
do (cl-incf func-depth)
|
|
|
|
|
and do (setq func-pitem pitem)
|
|
|
|
|
finally return (if (eq func-depth 1) func-pitem)))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defun js--beginning-of-defun-nested ()
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Helper function for `js--beginning-of-defun'.
|
|
|
|
|
Return the pitem of the function we went to the beginning of."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(or
|
|
|
|
|
;; Look for the smallest function that encloses point...
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cl-loop for pitem in (js--parse-state-at-point)
|
|
|
|
|
if (and (eq 'function (js--pitem-type pitem))
|
|
|
|
|
(js--inside-pitem-p pitem))
|
|
|
|
|
do (goto-char (js--pitem-h-begin pitem))
|
|
|
|
|
and return pitem)
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
;; ...and if that isn't found, look for the previous top-level
|
|
|
|
|
;; defun
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cl-loop for pstate = (js--backward-pstate)
|
|
|
|
|
while pstate
|
|
|
|
|
if (js--pstate-is-toplevel-defun pstate)
|
|
|
|
|
do (goto-char (js--pitem-h-begin it))
|
|
|
|
|
and return it)))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defun js--beginning-of-defun-flat ()
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Helper function for `js-beginning-of-defun'."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(let ((pstate (js--beginning-of-defun-raw)))
|
|
|
|
|
(when pstate
|
|
|
|
|
(goto-char (js--pitem-h-begin (car pstate))))))
|
|
|
|
|
|
2009-08-15 01:04:14 +00:00
|
|
|
|
(defun js-beginning-of-defun (&optional arg)
|
|
|
|
|
"Value of `beginning-of-defun-function' for `js-mode'."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(setq arg (or arg 1))
|
|
|
|
|
(while (and (not (eobp)) (< arg 0))
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cl-incf arg)
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(when (and (not js-flat-functions)
|
|
|
|
|
(or (eq (js-syntactic-context) 'function)
|
|
|
|
|
(js--function-prologue-beginning)))
|
2009-08-15 01:04:14 +00:00
|
|
|
|
(js-end-of-defun))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(if (js--re-search-forward
|
|
|
|
|
"\\_<function\\_>" nil t)
|
|
|
|
|
(goto-char (js--function-prologue-beginning))
|
|
|
|
|
(goto-char (point-max))))
|
|
|
|
|
|
|
|
|
|
(while (> arg 0)
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cl-decf arg)
|
2009-08-14 23:02:38 +00:00
|
|
|
|
;; If we're just past the end of a function, the user probably wants
|
|
|
|
|
;; to go to the beginning of *that* function
|
|
|
|
|
(when (eq (char-before) ?})
|
|
|
|
|
(backward-char))
|
|
|
|
|
|
|
|
|
|
(let ((prologue-begin (js--function-prologue-beginning)))
|
|
|
|
|
(cond ((and prologue-begin (< prologue-begin (point)))
|
|
|
|
|
(goto-char prologue-begin))
|
|
|
|
|
|
|
|
|
|
(js-flat-functions
|
|
|
|
|
(js--beginning-of-defun-flat))
|
|
|
|
|
(t
|
|
|
|
|
(js--beginning-of-defun-nested))))))
|
|
|
|
|
|
|
|
|
|
(defun js--flush-caches (&optional beg ignored)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Flush the `js-mode' syntax cache after position BEG.
|
* international/ucs-normalize.el (ucs-normalize-sort, quick-check-list):
Fix typos in docstrings.
* progmodes/js.el (js--macro-decl-re): Doc fix.
(js--plain-method-re, js--split-name): Refloc docstring.
(js--class-styles, js--make-merged-item, js--splice-into-items):
Fix typos in docstrings; reflow docstrings.
(js--maybe-join, js--function-prologue-beginning, js--flush-caches)
(js--variable-decl-matcher, js--inside-pitem-p)
(js--parse-state-at-point, js--get-all-known-symbols)
(js--symbol-history, js-find-symbol, js--js-references)
(js--moz-interactor, js--js-encode-value, js--read-tab):
Fix typos in docstrings.
2009-08-28 18:22:30 +00:00
|
|
|
|
BEG defaults to `point-min', meaning to flush the entire cache."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(interactive)
|
|
|
|
|
(setq beg (or beg (save-restriction (widen) (point-min))))
|
|
|
|
|
(setq js--cache-end (min js--cache-end beg)))
|
|
|
|
|
|
2011-04-22 20:44:26 +02:00
|
|
|
|
(defmacro js--debug (&rest _arguments)
|
2009-08-14 23:02:38 +00:00
|
|
|
|
;; `(message ,@arguments)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
(defun js--ensure-cache--pop-if-ended (open-items paren-depth)
|
|
|
|
|
(let ((top-item (car open-items)))
|
|
|
|
|
(when (<= paren-depth (js--pitem-paren-depth top-item))
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cl-assert (not (get-text-property (1- (point)) 'js-pend)))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(put-text-property (1- (point)) (point) 'js--pend top-item)
|
|
|
|
|
(setf (js--pitem-b-end top-item) (point))
|
|
|
|
|
(setq open-items
|
|
|
|
|
;; open-items must contain at least two items for this to
|
|
|
|
|
;; work, but because we push a dummy item to start with,
|
|
|
|
|
;; that assumption holds.
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cons (js--pitem-add-child (cl-second open-items) top-item)
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(cddr open-items)))))
|
|
|
|
|
open-items)
|
|
|
|
|
|
|
|
|
|
(defmacro js--ensure-cache--update-parse ()
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Helper function for `js--ensure-cache'.
|
|
|
|
|
Update parsing information up to point, referring to parse,
|
|
|
|
|
prev-parse-point, goal-point, and open-items bound lexically in
|
|
|
|
|
the body of `js--ensure-cache'."
|
2018-11-05 01:22:15 +01:00
|
|
|
|
'(progn
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(setq goal-point (point))
|
|
|
|
|
(goto-char prev-parse-point)
|
|
|
|
|
(while (progn
|
|
|
|
|
(setq open-items (js--ensure-cache--pop-if-ended
|
|
|
|
|
open-items (car parse)))
|
|
|
|
|
;; Make sure parse-partial-sexp doesn't stop because we *entered*
|
|
|
|
|
;; the given depth -- i.e., make sure we're deeper than the target
|
|
|
|
|
;; depth.
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cl-assert (> (nth 0 parse)
|
2018-11-05 01:22:15 +01:00
|
|
|
|
(js--pitem-paren-depth (car open-items))))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(setq parse (parse-partial-sexp
|
|
|
|
|
prev-parse-point goal-point
|
|
|
|
|
(js--pitem-paren-depth (car open-items))
|
|
|
|
|
nil parse))
|
|
|
|
|
|
|
|
|
|
;; (let ((overlay (make-overlay prev-parse-point (point))))
|
|
|
|
|
;; (overlay-put overlay 'face '(:background "red"))
|
|
|
|
|
;; (unwind-protect
|
|
|
|
|
;; (progn
|
|
|
|
|
;; (js--debug "parsed: %S" parse)
|
|
|
|
|
;; (sit-for 1))
|
|
|
|
|
;; (delete-overlay overlay)))
|
|
|
|
|
|
|
|
|
|
(setq prev-parse-point (point))
|
|
|
|
|
(< (point) goal-point)))
|
|
|
|
|
|
|
|
|
|
(setq open-items (js--ensure-cache--pop-if-ended
|
|
|
|
|
open-items (car parse)))))
|
|
|
|
|
|
|
|
|
|
(defun js--show-cache-at-point ()
|
|
|
|
|
(interactive)
|
|
|
|
|
(require 'pp)
|
|
|
|
|
(let ((prop (get-text-property (point) 'js--pstate)))
|
|
|
|
|
(with-output-to-temp-buffer "*Help*"
|
|
|
|
|
(pp prop))))
|
|
|
|
|
|
|
|
|
|
(defun js--split-name (string)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Split a JavaScript name into its dot-separated parts.
|
* international/ucs-normalize.el (ucs-normalize-sort, quick-check-list):
Fix typos in docstrings.
* progmodes/js.el (js--macro-decl-re): Doc fix.
(js--plain-method-re, js--split-name): Refloc docstring.
(js--class-styles, js--make-merged-item, js--splice-into-items):
Fix typos in docstrings; reflow docstrings.
(js--maybe-join, js--function-prologue-beginning, js--flush-caches)
(js--variable-decl-matcher, js--inside-pitem-p)
(js--parse-state-at-point, js--get-all-known-symbols)
(js--symbol-history, js-find-symbol, js--js-references)
(js--moz-interactor, js--js-encode-value, js--read-tab):
Fix typos in docstrings.
2009-08-28 18:22:30 +00:00
|
|
|
|
This also removes any prototype parts from the split name
|
|
|
|
|
\(unless the name is just \"prototype\" to start with)."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(let ((name (save-match-data
|
|
|
|
|
(split-string string "\\." t))))
|
|
|
|
|
(unless (and (= (length name) 1)
|
|
|
|
|
(equal (car name) "prototype"))
|
|
|
|
|
|
|
|
|
|
(setq name (remove "prototype" name)))))
|
|
|
|
|
|
2009-08-15 01:04:14 +00:00
|
|
|
|
(defvar js--guess-function-name-start nil)
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defun js--guess-function-name (position)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Guess the name of the JavaScript function at POSITION.
|
|
|
|
|
POSITION should be just after the end of the word \"function\".
|
|
|
|
|
Return the name of the function, or nil if the name could not be
|
|
|
|
|
guessed.
|
|
|
|
|
|
|
|
|
|
This function clobbers match data. If we find the preamble
|
|
|
|
|
begins earlier than expected while guessing the function name,
|
|
|
|
|
set `js--guess-function-name-start' to that position; otherwise,
|
|
|
|
|
set that variable to nil."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(setq js--guess-function-name-start nil)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char position)
|
|
|
|
|
(forward-line 0)
|
|
|
|
|
(cond
|
|
|
|
|
((looking-at js--function-heading-3-re)
|
|
|
|
|
(and (eq (match-end 0) position)
|
|
|
|
|
(setq js--guess-function-name-start (match-beginning 1))
|
|
|
|
|
(match-string-no-properties 1)))
|
|
|
|
|
|
|
|
|
|
((looking-at js--function-heading-2-re)
|
|
|
|
|
(and (eq (match-end 0) position)
|
|
|
|
|
(setq js--guess-function-name-start (match-beginning 1))
|
|
|
|
|
(match-string-no-properties 1))))))
|
|
|
|
|
|
|
|
|
|
(defun js--clear-stale-cache ()
|
|
|
|
|
;; Clear any endings that occur after point
|
|
|
|
|
(let (end-prop)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(while (setq end-prop (js--forward-text-property
|
|
|
|
|
'js--pend))
|
|
|
|
|
(setf (js--pitem-b-end end-prop) nil))))
|
|
|
|
|
|
|
|
|
|
;; Remove any cache properties after this point
|
|
|
|
|
(remove-text-properties (point) (point-max)
|
|
|
|
|
'(js--pstate t js--pend t)))
|
|
|
|
|
|
|
|
|
|
(defun js--ensure-cache (&optional limit)
|
|
|
|
|
"Ensures brace cache is valid up to the character before LIMIT.
|
|
|
|
|
LIMIT defaults to point."
|
|
|
|
|
(setq limit (or limit (point)))
|
|
|
|
|
(when (< js--cache-end limit)
|
|
|
|
|
|
|
|
|
|
(c-save-buffer-state
|
|
|
|
|
(open-items
|
|
|
|
|
parse
|
|
|
|
|
prev-parse-point
|
|
|
|
|
name
|
|
|
|
|
case-fold-search
|
|
|
|
|
filtered-class-styles
|
2012-04-26 08:43:28 -04:00
|
|
|
|
goal-point)
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
;; Figure out which class styles we need to look for
|
|
|
|
|
(setq filtered-class-styles
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cl-loop for style in js--class-styles
|
|
|
|
|
if (memq (plist-get style :framework)
|
|
|
|
|
js-enabled-frameworks)
|
|
|
|
|
collect style))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(save-excursion
|
|
|
|
|
(save-restriction
|
|
|
|
|
(widen)
|
|
|
|
|
|
|
|
|
|
;; Find last known good position
|
|
|
|
|
(goto-char js--cache-end)
|
|
|
|
|
(unless (bobp)
|
|
|
|
|
(setq open-items (get-text-property
|
|
|
|
|
(1- (point)) 'js--pstate))
|
|
|
|
|
|
|
|
|
|
(unless open-items
|
|
|
|
|
(goto-char (previous-single-property-change
|
|
|
|
|
(point) 'js--pstate nil (point-min)))
|
|
|
|
|
|
|
|
|
|
(unless (bobp)
|
|
|
|
|
(setq open-items (get-text-property (1- (point))
|
|
|
|
|
'js--pstate))
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cl-assert open-items))))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(unless open-items
|
|
|
|
|
;; Make a placeholder for the top-level definition
|
|
|
|
|
(setq open-items (list js--initial-pitem)))
|
|
|
|
|
|
|
|
|
|
(setq parse (syntax-ppss))
|
|
|
|
|
(setq prev-parse-point (point))
|
|
|
|
|
|
|
|
|
|
(js--clear-stale-cache)
|
|
|
|
|
|
|
|
|
|
(narrow-to-region (point-min) limit)
|
|
|
|
|
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cl-loop while (re-search-forward js--quick-match-re-func nil t)
|
|
|
|
|
for orig-match-start = (goto-char (match-beginning 0))
|
|
|
|
|
for orig-match-end = (match-end 0)
|
|
|
|
|
do (js--ensure-cache--update-parse)
|
|
|
|
|
for orig-depth = (nth 0 parse)
|
|
|
|
|
|
|
|
|
|
;; Each of these conditions should return non-nil if
|
|
|
|
|
;; we should add a new item and leave point at the end
|
|
|
|
|
;; of the new item's header (h-end in the
|
|
|
|
|
;; js--pitem diagram). This point is the one
|
|
|
|
|
;; after the last character we need to unambiguously
|
|
|
|
|
;; detect this construct. If one of these evaluates to
|
|
|
|
|
;; nil, the location of the point is ignored.
|
|
|
|
|
if (cond
|
|
|
|
|
;; In comment or string
|
|
|
|
|
((nth 8 parse) nil)
|
|
|
|
|
|
|
|
|
|
;; Regular function declaration
|
|
|
|
|
((and (looking-at "\\_<function\\_>")
|
|
|
|
|
(setq name (js--forward-function-decl)))
|
|
|
|
|
|
|
|
|
|
(when (eq name t)
|
|
|
|
|
(setq name (js--guess-function-name orig-match-end))
|
|
|
|
|
(if name
|
|
|
|
|
(when js--guess-function-name-start
|
|
|
|
|
(setq orig-match-start
|
|
|
|
|
js--guess-function-name-start))
|
|
|
|
|
|
|
|
|
|
(setq name t)))
|
|
|
|
|
|
|
|
|
|
(cl-assert (eq (char-after) ?{))
|
|
|
|
|
(forward-char)
|
|
|
|
|
(make-js--pitem
|
|
|
|
|
:paren-depth orig-depth
|
|
|
|
|
:h-begin orig-match-start
|
|
|
|
|
:type 'function
|
|
|
|
|
:name (if (eq name t)
|
|
|
|
|
name
|
|
|
|
|
(js--split-name name))))
|
|
|
|
|
|
|
|
|
|
;; Macro
|
|
|
|
|
((looking-at js--macro-decl-re)
|
|
|
|
|
|
|
|
|
|
;; Macros often contain unbalanced parentheses.
|
|
|
|
|
;; Make sure that h-end is at the textual end of
|
|
|
|
|
;; the macro no matter what the parenthesis say.
|
|
|
|
|
(c-end-of-macro)
|
|
|
|
|
(js--ensure-cache--update-parse)
|
|
|
|
|
|
|
|
|
|
(make-js--pitem
|
|
|
|
|
:paren-depth (nth 0 parse)
|
|
|
|
|
:h-begin orig-match-start
|
|
|
|
|
:type 'macro
|
|
|
|
|
:name (list (match-string-no-properties 1))))
|
|
|
|
|
|
|
|
|
|
;; "Prototype function" declaration
|
|
|
|
|
((looking-at js--plain-method-re)
|
|
|
|
|
(goto-char (match-beginning 3))
|
|
|
|
|
(when (save-match-data
|
|
|
|
|
(js--forward-function-decl))
|
|
|
|
|
(forward-char)
|
|
|
|
|
(make-js--pitem
|
|
|
|
|
:paren-depth orig-depth
|
|
|
|
|
:h-begin orig-match-start
|
|
|
|
|
:type 'function
|
|
|
|
|
:name (nconc (js--split-name
|
|
|
|
|
(match-string-no-properties 1))
|
|
|
|
|
(list (match-string-no-properties 2))))))
|
|
|
|
|
|
|
|
|
|
;; Class definition
|
|
|
|
|
((cl-loop
|
|
|
|
|
with syntactic-context =
|
|
|
|
|
(js--syntactic-context-from-pstate open-items)
|
|
|
|
|
for class-style in filtered-class-styles
|
|
|
|
|
if (and (memq syntactic-context
|
|
|
|
|
(plist-get class-style :contexts))
|
|
|
|
|
(looking-at (plist-get class-style
|
|
|
|
|
:class-decl)))
|
|
|
|
|
do (goto-char (match-end 0))
|
|
|
|
|
and return
|
|
|
|
|
(make-js--pitem
|
|
|
|
|
:paren-depth orig-depth
|
|
|
|
|
:h-begin orig-match-start
|
|
|
|
|
:type class-style
|
|
|
|
|
:name (js--split-name
|
|
|
|
|
(match-string-no-properties 1))))))
|
|
|
|
|
|
|
|
|
|
do (js--ensure-cache--update-parse)
|
|
|
|
|
and do (push it open-items)
|
|
|
|
|
and do (put-text-property
|
|
|
|
|
(1- (point)) (point) 'js--pstate open-items)
|
|
|
|
|
else do (goto-char orig-match-end))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(goto-char limit)
|
|
|
|
|
(js--ensure-cache--update-parse)
|
|
|
|
|
(setq js--cache-end limit)
|
|
|
|
|
(setq js--last-parse-pos limit)
|
|
|
|
|
(setq js--state-at-last-parse-pos open-items)
|
|
|
|
|
)))))
|
|
|
|
|
|
|
|
|
|
(defun js--end-of-defun-flat ()
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Helper function for `js-end-of-defun'."
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cl-loop while (js--re-search-forward "}" nil t)
|
|
|
|
|
do (js--ensure-cache)
|
|
|
|
|
if (get-text-property (1- (point)) 'js--pend)
|
|
|
|
|
if (eq 'function (js--pitem-type it))
|
|
|
|
|
return t
|
|
|
|
|
finally do (goto-char (point-max))))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defun js--end-of-defun-nested ()
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Helper function for `js-end-of-defun'."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(message "test")
|
|
|
|
|
(let* (pitem
|
|
|
|
|
(this-end (save-excursion
|
|
|
|
|
(and (setq pitem (js--beginning-of-defun-nested))
|
|
|
|
|
(js--pitem-goto-h-end pitem)
|
|
|
|
|
(progn (backward-char)
|
|
|
|
|
(forward-list)
|
|
|
|
|
(point)))))
|
|
|
|
|
found)
|
|
|
|
|
|
|
|
|
|
(if (and this-end (< (point) this-end))
|
|
|
|
|
;; We're already inside a function; just go to its end.
|
|
|
|
|
(goto-char this-end)
|
|
|
|
|
|
|
|
|
|
;; Otherwise, go to the end of the next function...
|
|
|
|
|
(while (and (js--re-search-forward "\\_<function\\_>" nil t)
|
|
|
|
|
(not (setq found (progn
|
|
|
|
|
(goto-char (match-beginning 0))
|
|
|
|
|
(js--forward-function-decl))))))
|
|
|
|
|
|
|
|
|
|
(if found (forward-list)
|
|
|
|
|
;; ... or eob.
|
|
|
|
|
(goto-char (point-max))))))
|
|
|
|
|
|
2009-08-15 01:04:14 +00:00
|
|
|
|
(defun js-end-of-defun (&optional arg)
|
|
|
|
|
"Value of `end-of-defun-function' for `js-mode'."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(setq arg (or arg 1))
|
|
|
|
|
(while (and (not (bobp)) (< arg 0))
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cl-incf arg)
|
2009-09-18 07:16:49 +00:00
|
|
|
|
(js-beginning-of-defun)
|
|
|
|
|
(js-beginning-of-defun)
|
|
|
|
|
(unless (bobp)
|
|
|
|
|
(js-end-of-defun)))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(while (> arg 0)
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cl-decf arg)
|
2009-08-14 23:02:38 +00:00
|
|
|
|
;; look for function backward. if we're inside it, go to that
|
|
|
|
|
;; function's end. otherwise, search for the next function's end and
|
|
|
|
|
;; go there
|
|
|
|
|
(if js-flat-functions
|
|
|
|
|
(js--end-of-defun-flat)
|
|
|
|
|
|
|
|
|
|
;; if we're doing nested functions, see whether we're in the
|
|
|
|
|
;; prologue. If we are, go to the end of the function; otherwise,
|
|
|
|
|
;; call js--end-of-defun-nested to do the real work
|
|
|
|
|
(let ((prologue-begin (js--function-prologue-beginning)))
|
|
|
|
|
(cond ((and prologue-begin (<= prologue-begin (point)))
|
|
|
|
|
(goto-char prologue-begin)
|
|
|
|
|
(re-search-forward "\\_<function")
|
|
|
|
|
(goto-char (match-beginning 0))
|
|
|
|
|
(js--forward-function-decl)
|
|
|
|
|
(forward-list))
|
|
|
|
|
|
|
|
|
|
(t (js--end-of-defun-nested)))))))
|
|
|
|
|
|
|
|
|
|
(defun js--beginning-of-macro (&optional lim)
|
|
|
|
|
(let ((here (point)))
|
|
|
|
|
(save-restriction
|
|
|
|
|
(if lim (narrow-to-region lim (point-max)))
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(while (eq (char-before (1- (point))) ?\\)
|
|
|
|
|
(forward-line -1))
|
|
|
|
|
(back-to-indentation)
|
|
|
|
|
(if (and (<= (point) here)
|
|
|
|
|
(looking-at js--opt-cpp-start))
|
|
|
|
|
t
|
|
|
|
|
(goto-char here)
|
|
|
|
|
nil))))
|
|
|
|
|
|
|
|
|
|
(defun js--backward-syntactic-ws (&optional lim)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Simple implementation of `c-backward-syntactic-ws' for `js-mode'."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(save-restriction
|
|
|
|
|
(when lim (narrow-to-region lim (point-max)))
|
|
|
|
|
|
|
|
|
|
(let ((in-macro (save-excursion (js--beginning-of-macro)))
|
|
|
|
|
(pos (point)))
|
|
|
|
|
|
|
|
|
|
(while (progn (unless in-macro (js--beginning-of-macro))
|
|
|
|
|
(forward-comment most-negative-fixnum)
|
|
|
|
|
(/= (point)
|
|
|
|
|
(prog1
|
|
|
|
|
pos
|
|
|
|
|
(setq pos (point)))))))))
|
|
|
|
|
|
|
|
|
|
(defun js--forward-syntactic-ws (&optional lim)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Simple implementation of `c-forward-syntactic-ws' for `js-mode'."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(save-restriction
|
|
|
|
|
(when lim (narrow-to-region (point-min) lim))
|
|
|
|
|
(let ((pos (point)))
|
|
|
|
|
(while (progn
|
|
|
|
|
(forward-comment most-positive-fixnum)
|
|
|
|
|
(when (eq (char-after) ?#)
|
|
|
|
|
(c-end-of-macro))
|
|
|
|
|
(/= (point)
|
|
|
|
|
(prog1
|
|
|
|
|
pos
|
|
|
|
|
(setq pos (point)))))))))
|
|
|
|
|
|
2009-08-15 01:04:14 +00:00
|
|
|
|
;; Like (up-list -1), but only considers lists that end nearby"
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(defun js--up-nearby-list ()
|
|
|
|
|
(save-restriction
|
2011-11-14 23:55:13 -08:00
|
|
|
|
;; Look at a very small region so our computation time doesn't
|
2009-08-14 23:02:38 +00:00
|
|
|
|
;; explode in pathological cases.
|
|
|
|
|
(narrow-to-region (max (point-min) (- (point) 500)) (point))
|
|
|
|
|
(up-list -1)))
|
|
|
|
|
|
|
|
|
|
(defun js--inside-param-list-p ()
|
2014-05-01 19:55:25 -04:00
|
|
|
|
"Return non-nil if point is in a function parameter list."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(ignore-errors
|
|
|
|
|
(save-excursion
|
|
|
|
|
(js--up-nearby-list)
|
|
|
|
|
(and (looking-at "(")
|
|
|
|
|
(progn (forward-symbol -1)
|
|
|
|
|
(or (looking-at "function")
|
|
|
|
|
(progn (forward-symbol -1)
|
|
|
|
|
(looking-at "function"))))))))
|
|
|
|
|
|
|
|
|
|
(defun js--inside-dojo-class-list-p ()
|
2014-05-01 19:55:25 -04:00
|
|
|
|
"Return non-nil if point is in a Dojo multiple-inheritance class block."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(ignore-errors
|
|
|
|
|
(save-excursion
|
|
|
|
|
(js--up-nearby-list)
|
|
|
|
|
(let ((list-begin (point)))
|
|
|
|
|
(forward-line 0)
|
|
|
|
|
(and (looking-at js--dojo-class-decl-re)
|
|
|
|
|
(goto-char (match-end 0))
|
|
|
|
|
(looking-at "\"\\s-*,\\s-*\\[")
|
|
|
|
|
(eq (match-end 0) (1+ list-begin)))))))
|
|
|
|
|
|
|
|
|
|
;;; Font Lock
|
|
|
|
|
(defun js--make-framework-matcher (framework &rest regexps)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Helper function for building `js--font-lock-keywords'.
|
|
|
|
|
Create a byte-compiled function for matching a concatenation of
|
|
|
|
|
REGEXPS, but only if FRAMEWORK is in `js-enabled-frameworks'."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(setq regexps (apply #'concat regexps))
|
|
|
|
|
(byte-compile
|
|
|
|
|
`(lambda (limit)
|
|
|
|
|
(when (memq (quote ,framework) js-enabled-frameworks)
|
|
|
|
|
(re-search-forward ,regexps limit t)))))
|
|
|
|
|
|
|
|
|
|
(defvar js--tmp-location nil)
|
|
|
|
|
(make-variable-buffer-local 'js--tmp-location)
|
|
|
|
|
|
|
|
|
|
(defun js--forward-destructuring-spec (&optional func)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Move forward over a JavaScript destructuring spec.
|
|
|
|
|
If FUNC is supplied, call it with no arguments before every
|
2014-05-01 19:55:25 -04:00
|
|
|
|
variable name in the spec. Return true if this was actually a
|
2009-08-15 01:04:14 +00:00
|
|
|
|
spec. FUNC must preserve the match data."
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(pcase (char-after)
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(?\[
|
|
|
|
|
(forward-char)
|
|
|
|
|
(while
|
|
|
|
|
(progn
|
|
|
|
|
(forward-comment most-positive-fixnum)
|
|
|
|
|
(cond ((memq (char-after) '(?\[ ?\{))
|
|
|
|
|
(js--forward-destructuring-spec func))
|
|
|
|
|
|
|
|
|
|
((eq (char-after) ?,)
|
|
|
|
|
(forward-char)
|
|
|
|
|
t)
|
|
|
|
|
|
|
|
|
|
((looking-at js--name-re)
|
|
|
|
|
(and func (funcall func))
|
|
|
|
|
(goto-char (match-end 0))
|
|
|
|
|
t))))
|
|
|
|
|
(when (eq (char-after) ?\])
|
|
|
|
|
(forward-char)
|
|
|
|
|
t))
|
|
|
|
|
|
|
|
|
|
(?\{
|
|
|
|
|
(forward-char)
|
|
|
|
|
(forward-comment most-positive-fixnum)
|
|
|
|
|
(while
|
|
|
|
|
(when (looking-at js--objfield-re)
|
|
|
|
|
(goto-char (match-end 0))
|
|
|
|
|
(forward-comment most-positive-fixnum)
|
|
|
|
|
(and (cond ((memq (char-after) '(?\[ ?\{))
|
|
|
|
|
(js--forward-destructuring-spec func))
|
|
|
|
|
((looking-at js--name-re)
|
|
|
|
|
(and func (funcall func))
|
|
|
|
|
(goto-char (match-end 0))
|
|
|
|
|
t))
|
|
|
|
|
(progn (forward-comment most-positive-fixnum)
|
|
|
|
|
(when (eq (char-after) ?\,)
|
|
|
|
|
(forward-char)
|
|
|
|
|
(forward-comment most-positive-fixnum)
|
|
|
|
|
t)))))
|
|
|
|
|
(when (eq (char-after) ?\})
|
|
|
|
|
(forward-char)
|
|
|
|
|
t))))
|
|
|
|
|
|
|
|
|
|
(defun js--variable-decl-matcher (limit)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Font-lock matcher for variable names in a variable declaration.
|
|
|
|
|
This is a cc-mode-style matcher that *always* fails, from the
|
* international/ucs-normalize.el (ucs-normalize-sort, quick-check-list):
Fix typos in docstrings.
* progmodes/js.el (js--macro-decl-re): Doc fix.
(js--plain-method-re, js--split-name): Refloc docstring.
(js--class-styles, js--make-merged-item, js--splice-into-items):
Fix typos in docstrings; reflow docstrings.
(js--maybe-join, js--function-prologue-beginning, js--flush-caches)
(js--variable-decl-matcher, js--inside-pitem-p)
(js--parse-state-at-point, js--get-all-known-symbols)
(js--symbol-history, js-find-symbol, js--js-references)
(js--moz-interactor, js--js-encode-value, js--read-tab):
Fix typos in docstrings.
2009-08-28 18:22:30 +00:00
|
|
|
|
point of view of font-lock. It applies highlighting directly with
|
|
|
|
|
`font-lock-apply-highlight'."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(condition-case nil
|
|
|
|
|
(save-restriction
|
|
|
|
|
(narrow-to-region (point-min) limit)
|
|
|
|
|
|
|
|
|
|
(let ((first t))
|
|
|
|
|
(forward-comment most-positive-fixnum)
|
|
|
|
|
(while
|
|
|
|
|
(and (or first
|
|
|
|
|
(when (eq (char-after) ?,)
|
|
|
|
|
(forward-char)
|
|
|
|
|
(forward-comment most-positive-fixnum)
|
|
|
|
|
t))
|
|
|
|
|
(cond ((looking-at js--name-re)
|
|
|
|
|
(font-lock-apply-highlight
|
|
|
|
|
'(0 font-lock-variable-name-face))
|
|
|
|
|
(goto-char (match-end 0)))
|
|
|
|
|
|
|
|
|
|
((save-excursion
|
|
|
|
|
(js--forward-destructuring-spec))
|
|
|
|
|
|
|
|
|
|
(js--forward-destructuring-spec
|
|
|
|
|
(lambda ()
|
|
|
|
|
(font-lock-apply-highlight
|
|
|
|
|
'(0 font-lock-variable-name-face)))))))
|
|
|
|
|
|
|
|
|
|
(forward-comment most-positive-fixnum)
|
|
|
|
|
(when (eq (char-after) ?=)
|
|
|
|
|
(forward-char)
|
|
|
|
|
(js--forward-expression)
|
|
|
|
|
(forward-comment most-positive-fixnum))
|
|
|
|
|
|
|
|
|
|
(setq first nil))))
|
|
|
|
|
|
|
|
|
|
;; Conditions to handle
|
|
|
|
|
(scan-error nil)
|
|
|
|
|
(end-of-buffer nil))
|
|
|
|
|
|
|
|
|
|
;; Matcher always "fails"
|
|
|
|
|
nil)
|
|
|
|
|
|
2019-02-17 00:38:01 -08:00
|
|
|
|
(defconst js-jsx--font-lock-keywords
|
|
|
|
|
`((js-jsx--match-tag-name 0 font-lock-function-name-face t)
|
2019-02-17 21:16:13 -08:00
|
|
|
|
(js-jsx--match-attribute-name 0 font-lock-variable-name-face t)
|
2019-03-08 16:29:02 -08:00
|
|
|
|
(js-jsx--match-text 0 'default t) ; “Undo” keyword fontification.
|
2019-02-17 21:16:13 -08:00
|
|
|
|
(js-jsx--match-tag-beg)
|
2019-03-08 16:29:02 -08:00
|
|
|
|
(js-jsx--match-tag-end)
|
|
|
|
|
(js-jsx--match-expr))
|
2019-02-17 21:16:13 -08:00
|
|
|
|
"JSX font lock faces and multiline text properties.")
|
2019-02-17 00:38:01 -08:00
|
|
|
|
|
|
|
|
|
(defun js-jsx--match-tag-name (limit)
|
|
|
|
|
"Match JSXBoundaryElement names, until LIMIT."
|
|
|
|
|
(when js-jsx-syntax
|
|
|
|
|
(let ((pos (next-single-char-property-change (point) 'js-jsx-tag-name nil limit))
|
|
|
|
|
value)
|
|
|
|
|
(when (and pos (> pos (point)))
|
|
|
|
|
(goto-char pos)
|
|
|
|
|
(or (and (setq value (get-text-property pos 'js-jsx-tag-name))
|
|
|
|
|
(progn (set-match-data value) t))
|
|
|
|
|
(js-jsx--match-tag-name limit))))))
|
|
|
|
|
|
|
|
|
|
(defun js-jsx--match-attribute-name (limit)
|
|
|
|
|
"Match JSXAttribute names, until LIMIT."
|
|
|
|
|
(when js-jsx-syntax
|
|
|
|
|
(let ((pos (next-single-char-property-change (point) 'js-jsx-attribute-name nil limit))
|
|
|
|
|
value)
|
|
|
|
|
(when (and pos (> pos (point)))
|
|
|
|
|
(goto-char pos)
|
|
|
|
|
(or (and (setq value (get-text-property pos 'js-jsx-attribute-name))
|
|
|
|
|
(progn (set-match-data value) t))
|
|
|
|
|
(js-jsx--match-attribute-name limit))))))
|
|
|
|
|
|
2019-03-08 16:29:02 -08:00
|
|
|
|
(defun js-jsx--match-text (limit)
|
|
|
|
|
"Match JSXText, until LIMIT."
|
|
|
|
|
(when js-jsx-syntax
|
|
|
|
|
(let ((pos (next-single-char-property-change (point) 'js-jsx-text nil limit))
|
|
|
|
|
value)
|
|
|
|
|
(when (and pos (> pos (point)))
|
|
|
|
|
(goto-char pos)
|
|
|
|
|
(or (and (setq value (get-text-property pos 'js-jsx-text))
|
|
|
|
|
(progn (set-match-data value)
|
|
|
|
|
(put-text-property (car value) (cadr value) 'font-lock-multiline t)
|
|
|
|
|
t))
|
|
|
|
|
(js-jsx--match-text limit))))))
|
|
|
|
|
|
2019-02-17 21:16:13 -08:00
|
|
|
|
(defun js-jsx--match-tag-beg (limit)
|
|
|
|
|
"Match JSXBoundaryElements from start, until LIMIT."
|
|
|
|
|
(when js-jsx-syntax
|
|
|
|
|
(let ((pos (next-single-char-property-change (point) 'js-jsx-tag-beg nil limit))
|
|
|
|
|
value)
|
|
|
|
|
(when (and pos (> pos (point)))
|
|
|
|
|
(goto-char pos)
|
|
|
|
|
(or (and (setq value (get-text-property pos 'js-jsx-tag-beg))
|
|
|
|
|
(progn (put-text-property pos (cdr value) 'font-lock-multiline t) t))
|
|
|
|
|
(js-jsx--match-tag-beg limit))))))
|
|
|
|
|
|
|
|
|
|
(defun js-jsx--match-tag-end (limit)
|
|
|
|
|
"Match JSXBoundaryElements from end, until LIMIT."
|
|
|
|
|
(when js-jsx-syntax
|
|
|
|
|
(let ((pos (next-single-char-property-change (point) 'js-jsx-tag-end nil limit))
|
|
|
|
|
value)
|
|
|
|
|
(when (and pos (> pos (point)))
|
|
|
|
|
(goto-char pos)
|
|
|
|
|
(or (and (setq value (get-text-property pos 'js-jsx-tag-end))
|
|
|
|
|
(progn (put-text-property value pos 'font-lock-multiline t) t))
|
|
|
|
|
(js-jsx--match-tag-end limit))))))
|
|
|
|
|
|
2019-03-08 16:29:02 -08:00
|
|
|
|
(defun js-jsx--match-expr (limit)
|
|
|
|
|
"Match JSXExpressionContainers, until LIMIT."
|
|
|
|
|
(when js-jsx-syntax
|
|
|
|
|
(let ((pos (next-single-char-property-change (point) 'js-jsx-expr nil limit))
|
|
|
|
|
value)
|
|
|
|
|
(when (and pos (> pos (point)))
|
|
|
|
|
(goto-char pos)
|
|
|
|
|
(or (and (setq value (get-text-property pos 'js-jsx-expr))
|
|
|
|
|
(progn (put-text-property pos value 'font-lock-multiline t) t))
|
|
|
|
|
(js-jsx--match-expr limit))))))
|
|
|
|
|
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(defconst js--font-lock-keywords-3
|
|
|
|
|
`(
|
|
|
|
|
;; This goes before keywords-2 so it gets used preferentially
|
|
|
|
|
;; instead of the keywords in keywords-2. Don't use override
|
|
|
|
|
;; because that will override syntactic fontification too, which
|
|
|
|
|
;; will fontify commented-out directives as if they weren't
|
|
|
|
|
;; commented out.
|
|
|
|
|
,@cpp-font-lock-keywords ; from font-lock.el
|
|
|
|
|
|
|
|
|
|
,@js--font-lock-keywords-2
|
|
|
|
|
|
|
|
|
|
("\\.\\(prototype\\)\\_>"
|
|
|
|
|
(1 font-lock-constant-face))
|
|
|
|
|
|
|
|
|
|
;; Highlights class being declared, in parts
|
|
|
|
|
(js--class-decl-matcher
|
|
|
|
|
,(concat "\\(" js--name-re "\\)\\(?:\\.\\|.*$\\)")
|
|
|
|
|
(goto-char (match-beginning 1))
|
|
|
|
|
nil
|
|
|
|
|
(1 font-lock-type-face))
|
|
|
|
|
|
|
|
|
|
;; Highlights parent class, in parts, if available
|
|
|
|
|
(js--class-decl-matcher
|
|
|
|
|
,(concat "\\(" js--name-re "\\)\\(?:\\.\\|.*$\\)")
|
|
|
|
|
(if (match-beginning 2)
|
|
|
|
|
(progn
|
|
|
|
|
(setq js--tmp-location (match-end 2))
|
|
|
|
|
(goto-char js--tmp-location)
|
|
|
|
|
(insert "=")
|
|
|
|
|
(goto-char (match-beginning 2)))
|
|
|
|
|
(setq js--tmp-location nil)
|
|
|
|
|
(goto-char (point-at-eol)))
|
|
|
|
|
(when js--tmp-location
|
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char js--tmp-location)
|
|
|
|
|
(delete-char 1)))
|
|
|
|
|
(1 font-lock-type-face))
|
|
|
|
|
|
|
|
|
|
;; Highlights parent class
|
|
|
|
|
(js--class-decl-matcher
|
|
|
|
|
(2 font-lock-type-face nil t))
|
|
|
|
|
|
|
|
|
|
;; Dojo needs its own matcher to override the string highlighting
|
|
|
|
|
(,(js--make-framework-matcher
|
|
|
|
|
'dojo
|
|
|
|
|
"^\\s-*dojo\\.declare\\s-*(\""
|
|
|
|
|
"\\(" js--dotted-name-re "\\)"
|
|
|
|
|
"\\(?:\"\\s-*,\\s-*\\(" js--dotted-name-re "\\)\\)?")
|
|
|
|
|
(1 font-lock-type-face t)
|
|
|
|
|
(2 font-lock-type-face nil t))
|
|
|
|
|
|
|
|
|
|
;; Match Dojo base classes. Of course Mojo has to be different
|
|
|
|
|
;; from everything else under the sun...
|
|
|
|
|
(,(js--make-framework-matcher
|
|
|
|
|
'dojo
|
|
|
|
|
"^\\s-*dojo\\.declare\\s-*(\""
|
|
|
|
|
"\\(" js--dotted-name-re "\\)\"\\s-*,\\s-*\\[")
|
|
|
|
|
,(concat "[[,]\\s-*\\(" js--dotted-name-re "\\)\\s-*"
|
|
|
|
|
"\\(?:\\].*$\\)?")
|
|
|
|
|
(backward-char)
|
|
|
|
|
(end-of-line)
|
|
|
|
|
(1 font-lock-type-face))
|
|
|
|
|
|
|
|
|
|
;; continued Dojo base-class list
|
|
|
|
|
(,(js--make-framework-matcher
|
|
|
|
|
'dojo
|
|
|
|
|
"^\\s-*" js--dotted-name-re "\\s-*[],]")
|
|
|
|
|
,(concat "\\(" js--dotted-name-re "\\)"
|
|
|
|
|
"\\s-*\\(?:\\].*$\\)?")
|
|
|
|
|
(if (save-excursion (backward-char)
|
|
|
|
|
(js--inside-dojo-class-list-p))
|
|
|
|
|
(forward-symbol -1)
|
|
|
|
|
(end-of-line))
|
|
|
|
|
(end-of-line)
|
|
|
|
|
(1 font-lock-type-face))
|
|
|
|
|
|
|
|
|
|
;; variable declarations
|
|
|
|
|
,(list
|
|
|
|
|
(concat "\\_<\\(const\\|var\\|let\\)\\_>\\|" js--basic-type-re)
|
|
|
|
|
(list #'js--variable-decl-matcher nil nil nil))
|
|
|
|
|
|
|
|
|
|
;; class instantiation
|
|
|
|
|
,(list
|
|
|
|
|
(concat "\\_<new\\_>\\s-+\\(" js--dotted-name-re "\\)")
|
|
|
|
|
(list 1 'font-lock-type-face))
|
|
|
|
|
|
|
|
|
|
;; instanceof
|
|
|
|
|
,(list
|
|
|
|
|
(concat "\\_<instanceof\\_>\\s-+\\(" js--dotted-name-re "\\)")
|
|
|
|
|
(list 1 'font-lock-type-face))
|
|
|
|
|
|
|
|
|
|
;; formal parameters
|
|
|
|
|
,(list
|
|
|
|
|
(concat
|
|
|
|
|
"\\_<function\\_>\\(\\s-+" js--name-re "\\)?\\s-*(\\s-*"
|
|
|
|
|
js--name-start-re)
|
|
|
|
|
(list (concat "\\(" js--name-re "\\)\\(\\s-*).*\\)?")
|
|
|
|
|
'(backward-char)
|
|
|
|
|
'(end-of-line)
|
|
|
|
|
'(1 font-lock-variable-name-face)))
|
|
|
|
|
|
|
|
|
|
;; continued formal parameter list
|
|
|
|
|
,(list
|
|
|
|
|
(concat
|
|
|
|
|
"^\\s-*" js--name-re "\\s-*[,)]")
|
|
|
|
|
(list js--name-re
|
|
|
|
|
'(if (save-excursion (backward-char)
|
|
|
|
|
(js--inside-param-list-p))
|
|
|
|
|
(forward-symbol -1)
|
|
|
|
|
(end-of-line))
|
|
|
|
|
'(end-of-line)
|
2019-02-17 00:38:01 -08:00
|
|
|
|
'(0 font-lock-variable-name-face)))
|
|
|
|
|
|
|
|
|
|
;; jsx (when enabled)
|
|
|
|
|
,@js-jsx--font-lock-keywords)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Level three font lock for `js-mode'.")
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defun js--inside-pitem-p (pitem)
|
* international/ucs-normalize.el (ucs-normalize-sort, quick-check-list):
Fix typos in docstrings.
* progmodes/js.el (js--macro-decl-re): Doc fix.
(js--plain-method-re, js--split-name): Refloc docstring.
(js--class-styles, js--make-merged-item, js--splice-into-items):
Fix typos in docstrings; reflow docstrings.
(js--maybe-join, js--function-prologue-beginning, js--flush-caches)
(js--variable-decl-matcher, js--inside-pitem-p)
(js--parse-state-at-point, js--get-all-known-symbols)
(js--symbol-history, js-find-symbol, js--js-references)
(js--moz-interactor, js--js-encode-value, js--read-tab):
Fix typos in docstrings.
2009-08-28 18:22:30 +00:00
|
|
|
|
"Return whether point is inside the given pitem's header or body."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(js--ensure-cache)
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cl-assert (js--pitem-h-begin pitem))
|
|
|
|
|
(cl-assert (js--pitem-paren-depth pitem))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(and (> (point) (js--pitem-h-begin pitem))
|
|
|
|
|
(or (null (js--pitem-b-end pitem))
|
|
|
|
|
(> (js--pitem-b-end pitem) (point)))))
|
|
|
|
|
|
|
|
|
|
(defun js--parse-state-at-point ()
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Parse the JavaScript program state at point.
|
|
|
|
|
Return a list of `js--pitem' instances that apply to point, most
|
* international/ucs-normalize.el (ucs-normalize-sort, quick-check-list):
Fix typos in docstrings.
* progmodes/js.el (js--macro-decl-re): Doc fix.
(js--plain-method-re, js--split-name): Refloc docstring.
(js--class-styles, js--make-merged-item, js--splice-into-items):
Fix typos in docstrings; reflow docstrings.
(js--maybe-join, js--function-prologue-beginning, js--flush-caches)
(js--variable-decl-matcher, js--inside-pitem-p)
(js--parse-state-at-point, js--get-all-known-symbols)
(js--symbol-history, js-find-symbol, js--js-references)
(js--moz-interactor, js--js-encode-value, js--read-tab):
Fix typos in docstrings.
2009-08-28 18:22:30 +00:00
|
|
|
|
specific first. In the worst case, the current toplevel instance
|
2009-08-15 01:04:14 +00:00
|
|
|
|
will be returned."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(save-excursion
|
|
|
|
|
(save-restriction
|
|
|
|
|
(widen)
|
|
|
|
|
(js--ensure-cache)
|
2011-04-22 20:44:26 +02:00
|
|
|
|
(let ((pstate (or (save-excursion
|
|
|
|
|
(js--backward-pstate))
|
|
|
|
|
(list js--initial-pitem))))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
;; Loop until we either hit a pitem at BOB or pitem ends after
|
|
|
|
|
;; point (or at point if we're at eob)
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cl-loop for pitem = (car pstate)
|
|
|
|
|
until (or (eq (js--pitem-type pitem)
|
|
|
|
|
'toplevel)
|
|
|
|
|
(js--inside-pitem-p pitem))
|
|
|
|
|
do (pop pstate))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
pstate))))
|
|
|
|
|
|
|
|
|
|
(defun js--syntactic-context-from-pstate (pstate)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Return the JavaScript syntactic context corresponding to PSTATE."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(let ((type (js--pitem-type (car pstate))))
|
|
|
|
|
(cond ((memq type '(function macro))
|
|
|
|
|
type)
|
|
|
|
|
((consp type)
|
|
|
|
|
'class)
|
|
|
|
|
(t 'toplevel))))
|
|
|
|
|
|
|
|
|
|
(defun js-syntactic-context ()
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Return the JavaScript syntactic context at point.
|
2011-11-19 01:18:31 -08:00
|
|
|
|
When called interactively, also display a message with that
|
2009-08-15 01:04:14 +00:00
|
|
|
|
context."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(interactive)
|
|
|
|
|
(let* ((syntactic-context (js--syntactic-context-from-pstate
|
|
|
|
|
(js--parse-state-at-point))))
|
|
|
|
|
|
2009-10-02 03:48:36 +00:00
|
|
|
|
(when (called-interactively-p 'interactive)
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(message "Syntactic context: %s" syntactic-context))
|
|
|
|
|
|
|
|
|
|
syntactic-context))
|
|
|
|
|
|
|
|
|
|
(defun js--class-decl-matcher (limit)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Font lock function used by `js-mode'.
|
|
|
|
|
This performs fontification according to `js--class-styles'."
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cl-loop initially (js--ensure-cache limit)
|
|
|
|
|
while (re-search-forward js--quick-match-re limit t)
|
|
|
|
|
for orig-end = (match-end 0)
|
|
|
|
|
do (goto-char (match-beginning 0))
|
|
|
|
|
if (cl-loop for style in js--class-styles
|
|
|
|
|
for decl-re = (plist-get style :class-decl)
|
|
|
|
|
if (and (memq (plist-get style :framework)
|
|
|
|
|
js-enabled-frameworks)
|
|
|
|
|
(memq (js-syntactic-context)
|
|
|
|
|
(plist-get style :contexts))
|
|
|
|
|
decl-re
|
|
|
|
|
(looking-at decl-re))
|
|
|
|
|
do (goto-char (match-end 0))
|
|
|
|
|
and return t)
|
|
|
|
|
return t
|
|
|
|
|
else do (goto-char orig-end)))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defconst js--font-lock-keywords
|
|
|
|
|
'(js--font-lock-keywords-3 js--font-lock-keywords-1
|
|
|
|
|
js--font-lock-keywords-2
|
|
|
|
|
js--font-lock-keywords-3)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Font lock keywords for `js-mode'. See `font-lock-keywords'.")
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
2017-02-25 10:27:48 -07:00
|
|
|
|
(defun js-font-lock-syntactic-face-function (state)
|
|
|
|
|
"Return syntactic face given STATE."
|
|
|
|
|
(if (nth 3 state)
|
|
|
|
|
font-lock-string-face
|
|
|
|
|
(if (save-excursion
|
|
|
|
|
(goto-char (nth 8 state))
|
|
|
|
|
(looking-at "/\\*\\*"))
|
|
|
|
|
font-lock-doc-face
|
|
|
|
|
font-lock-comment-face)))
|
|
|
|
|
|
2017-02-05 11:40:18 -07:00
|
|
|
|
(defconst js--syntax-propertize-regexp-regexp
|
|
|
|
|
(rx
|
|
|
|
|
;; Start of regexp.
|
|
|
|
|
"/"
|
|
|
|
|
(0+ (or
|
|
|
|
|
;; Match characters outside of a character class.
|
|
|
|
|
(not (any ?\[ ?/ ?\\))
|
|
|
|
|
;; Match backslash quoted characters.
|
|
|
|
|
(and "\\" not-newline)
|
|
|
|
|
;; Match character class.
|
|
|
|
|
(and
|
|
|
|
|
"["
|
|
|
|
|
(0+ (or
|
|
|
|
|
(not (any ?\] ?\\))
|
|
|
|
|
(and "\\" not-newline)))
|
|
|
|
|
"]")))
|
2017-03-13 21:53:59 +01:00
|
|
|
|
(group (zero-or-one "/")))
|
2017-02-05 11:40:18 -07:00
|
|
|
|
"Regular expression matching a JavaScript regexp literal.")
|
2014-12-23 11:17:55 -05:00
|
|
|
|
|
2011-08-12 11:32:39 -04:00
|
|
|
|
(defun js-syntax-propertize-regexp (end)
|
2014-12-23 11:17:55 -05:00
|
|
|
|
(let ((ppss (syntax-ppss)))
|
|
|
|
|
(when (eq (nth 3 ppss) ?/)
|
|
|
|
|
;; A /.../ regexp.
|
2017-02-05 11:40:18 -07:00
|
|
|
|
(goto-char (nth 8 ppss))
|
2017-03-13 21:53:59 +01:00
|
|
|
|
(when (looking-at js--syntax-propertize-regexp-regexp)
|
|
|
|
|
;; Don't touch text after END.
|
|
|
|
|
(when (> end (match-end 1))
|
|
|
|
|
(setq end (match-end 1)))
|
|
|
|
|
(put-text-property (match-beginning 1) end
|
2017-02-05 11:40:18 -07:00
|
|
|
|
'syntax-table (string-to-syntax "\"/"))
|
2017-03-13 21:53:59 +01:00
|
|
|
|
(goto-char end)))))
|
2011-08-12 11:32:39 -04:00
|
|
|
|
|
2019-02-11 03:00:34 -08:00
|
|
|
|
(defconst js--unary-keyword-re
|
|
|
|
|
(js--regexp-opt-symbol '("await" "delete" "typeof" "void" "yield"))
|
|
|
|
|
"Regexp matching unary operator keywords.")
|
|
|
|
|
|
|
|
|
|
(defun js--unary-keyword-p (string)
|
|
|
|
|
"Check if STRING is a unary operator keyword in JavaScript."
|
|
|
|
|
(string-match-p js--unary-keyword-re string))
|
|
|
|
|
|
2019-02-17 21:16:13 -08:00
|
|
|
|
(defun js--syntax-propertize-extend-region (start end)
|
|
|
|
|
"Extend the START-END region for propertization, if necessary.
|
|
|
|
|
For use by `syntax-propertize-extend-region-functions'."
|
|
|
|
|
(if js-jsx-syntax (js-jsx--syntax-propertize-extend-region start end)))
|
|
|
|
|
|
|
|
|
|
(defun js-jsx--syntax-propertize-extend-region (start end)
|
|
|
|
|
"Extend the START-END region for propertization, if necessary.
|
|
|
|
|
If any “>” in the region appears to be the end of a tag starting
|
|
|
|
|
before the start of the region, extend region backwards to the
|
|
|
|
|
start of that tag so parsing may proceed from that point.
|
|
|
|
|
For use by `syntax-propertize-extend-region-functions'."
|
|
|
|
|
(let (new-start
|
|
|
|
|
forward-sexp-function ; Use the Lisp version.
|
|
|
|
|
parse-sexp-lookup-properties) ; Fix backward-sexp error here.
|
|
|
|
|
(catch 'stop
|
|
|
|
|
(goto-char start)
|
|
|
|
|
(while (re-search-forward ">" end t)
|
|
|
|
|
(catch 'continue
|
|
|
|
|
;; Check if this is really a right shift bitwise operator
|
|
|
|
|
;; (“>>” or “>>>”).
|
|
|
|
|
(unless (or (eq (char-before (1- (point))) ?>)
|
|
|
|
|
(eq (char-after) ?>))
|
|
|
|
|
(save-excursion
|
|
|
|
|
(backward-char)
|
|
|
|
|
(while (progn (if (= (point) (point-min)) (throw 'continue nil))
|
|
|
|
|
(/= (char-before) ?<))
|
|
|
|
|
(skip-chars-backward " \t\n")
|
|
|
|
|
(if (= (point) (point-min)) (throw 'continue nil))
|
|
|
|
|
(cond
|
|
|
|
|
((memq (char-before) '(?\" ?\' ?\` ?\}))
|
|
|
|
|
(condition-case nil
|
|
|
|
|
(backward-sexp)
|
|
|
|
|
(scan-error (throw 'continue nil))))
|
|
|
|
|
((memq (char-before) '(?\/ ?\=)) (backward-char))
|
|
|
|
|
((looking-back js--dotted-name-re (line-beginning-position) t)
|
|
|
|
|
(goto-char (match-beginning 0)))
|
|
|
|
|
(t (throw 'continue nil))))
|
|
|
|
|
(when (< (point) start)
|
|
|
|
|
(setq new-start (1- (point)))
|
|
|
|
|
(throw 'stop nil)))))))
|
|
|
|
|
(if new-start (cons new-start end))))
|
|
|
|
|
|
2019-03-08 16:29:02 -08:00
|
|
|
|
(defconst js-jsx--tag-re
|
|
|
|
|
(concat "<\\s-*\\("
|
|
|
|
|
"[/>]" ; JSXClosingElement, or JSXOpeningFragment, or JSXClosingFragment
|
|
|
|
|
"\\|"
|
|
|
|
|
js--dotted-name-re "\\s-*[" js--name-start-chars "{/>]" ; JSXOpeningElement
|
|
|
|
|
"\\)")
|
|
|
|
|
"Regexp unambiguously matching a JSXBoundaryElement.")
|
|
|
|
|
|
|
|
|
|
(defun js-jsx--matched-tag-type ()
|
|
|
|
|
"Determine the tag type of the last match to `js-jsx--tag-re'.
|
|
|
|
|
Return `close' for a JSXClosingElement/JSXClosingFragment match,
|
|
|
|
|
return `self-closing' for some self-closing JSXOpeningElements,
|
|
|
|
|
else return `other'."
|
|
|
|
|
(let ((chars (vconcat (match-string 1))))
|
|
|
|
|
(cond
|
|
|
|
|
((= (aref chars 0) ?/) 'close)
|
|
|
|
|
((= (aref chars (1- (length chars))) ?/) 'self-closing)
|
|
|
|
|
(t 'other))))
|
|
|
|
|
|
|
|
|
|
(defconst js-jsx--self-closing-re "/\\s-*>"
|
|
|
|
|
"Regexp matching the end of a self-closing JSXOpeningElement.")
|
|
|
|
|
|
|
|
|
|
(defun js-jsx--matching-close-tag-pos ()
|
|
|
|
|
"Return position of the closer of the opener before point.
|
|
|
|
|
Assuming a JSXOpeningElement or a JSXOpeningFragment is
|
|
|
|
|
immediately before point, find a matching JSXClosingElement or
|
|
|
|
|
JSXClosingFragment, skipping over any nested JSXElements to find
|
|
|
|
|
the match. Return nil if a match can’t be found."
|
|
|
|
|
(let ((tag-stack 1) self-closing-pos type)
|
|
|
|
|
(catch 'stop
|
|
|
|
|
(while (re-search-forward js-jsx--tag-re nil t)
|
|
|
|
|
(setq type (js-jsx--matched-tag-type))
|
|
|
|
|
;; Balance the total of self-closing tags that we subtract
|
|
|
|
|
;; from the stack, ignoring those tags which are never added
|
|
|
|
|
;; to the stack (see below).
|
|
|
|
|
(unless (eq type 'self-closing)
|
|
|
|
|
(when (and self-closing-pos (> (point) self-closing-pos))
|
|
|
|
|
(setq tag-stack (1- tag-stack))))
|
|
|
|
|
(if (eq type 'close)
|
|
|
|
|
(progn
|
|
|
|
|
(setq tag-stack (1- tag-stack))
|
|
|
|
|
(when (= tag-stack 0)
|
|
|
|
|
(throw 'stop (match-beginning 0))))
|
|
|
|
|
;; Tags that we know are self-closing aren’t added to the
|
|
|
|
|
;; stack at all, because we only close the ones that we have
|
|
|
|
|
;; anticipated after moving past those anticipated tags’
|
|
|
|
|
;; ends, and if a self-closing tag is the first tag we
|
|
|
|
|
;; encounter in this loop, then it will never be anticipated
|
|
|
|
|
;; (due to an optimization where we sometimes can avoid
|
|
|
|
|
;; looking for self-closing tags).
|
|
|
|
|
(unless (eq type 'self-closing)
|
|
|
|
|
(setq tag-stack (1+ tag-stack))))
|
|
|
|
|
;; Don’t needlessly recalculate.
|
|
|
|
|
(unless (and self-closing-pos (<= (point) self-closing-pos))
|
|
|
|
|
(setq self-closing-pos nil) ; Reset if recalculating.
|
|
|
|
|
(save-excursion
|
|
|
|
|
;; Anticipate a self-closing tag that we should make sure
|
|
|
|
|
;; to subtract from the tag stack once we move past its
|
|
|
|
|
;; end; we might might miss the end otherwise, due to the
|
|
|
|
|
;; regexp-matching method we use to detect tags.
|
|
|
|
|
(when (re-search-forward js-jsx--self-closing-re nil t)
|
|
|
|
|
(setq self-closing-pos (match-beginning 0)))))))))
|
|
|
|
|
|
|
|
|
|
(defun js-jsx--enclosing-curly-pos ()
|
|
|
|
|
"Return position of enclosing “{” in a “{/}” pair about point."
|
|
|
|
|
(let ((parens (reverse (nth 9 (syntax-ppss)))) paren-pos curly-pos)
|
|
|
|
|
(while
|
|
|
|
|
(and
|
|
|
|
|
(setq paren-pos (car parens))
|
|
|
|
|
(not (when (= (char-after paren-pos) ?{)
|
|
|
|
|
(setq curly-pos paren-pos)))
|
|
|
|
|
(setq parens (cdr parens))))
|
|
|
|
|
curly-pos))
|
|
|
|
|
|
Indent JSX as parsed in a JS context
Fixes the following issues (and re-fixes indentation issues initially
fixed but later re-broken by previous commits in the process of adding
comprehensive JSX support):
- https://github.com/mooz/js2-mode/issues/389#issuecomment-390766873
- https://github.com/mooz/js2-mode/issues/482
- Bug#32158
- https://github.com/mooz/js2-mode/issues/462
Previously, we delegated to sgml-mode functions for JSX indentation.
However, there were some problems with this approach:
- sgml-mode does not anticipate tags inside attributes when indenting,
which compromises JSX indentation inside JSXExpressionContainers
inside JSXAttributes.
- In previous iterations to provide comprehensive JSX support, it
proved tedious to disambiguate “<” and “>” as JS inequality
operators and arrow functions from opening and closing angle
brackets as part of SGML tags. That code evolved into a more
complete JSX parsing implementation for syntax-propertize rules for
font-locking, discarding the superfluous “<”/“>” disambiguation in
anticipation of using the improved JSX analysis for indentation.
- Using sgml-mode functions, we controlled JSX indentation using SGML
variables. However, JSX is a different thing than SGML; referencing
SGML in JS was a leaky abstraction.
To resolve these issues, use the text properties added by the JSX
syntax-propertize code to determine the boundaries of various aspects
of JSX syntax, and reimplement the sgml-mode indentation code in
js-mode with better respect to JSX indentation conventions.
* lisp/progmodes/js.el (js-jsx-attribute-offset): New variable to
provide a way for users to still control JSX attribute offsets as they
could with sgml-attribute-offset before. The value of this feature is
dubious IMO, but it’s trivial to keep it, so let’s do it just in case.
(js-jsx--goto-outermost-enclosing-curly): New function.
(js-jsx--enclosing-tag-pos): Refactor to be unbounded by curlies, so
this function can be used to find JSXExpressionContainers within JSX.
Fix bug where an enclosing JSXElement couldn’t be found when point was
at the start of its JSXClosingElement. Return the JSXClosingElement’s
position as well, so the JSXClosingElement can be indentified when
indenting and be indented like the matching JSXOpeningElement.
(js-jsx--at-enclosing-tag-child-p): js-jsx--enclosing-tag-pos now
returns a list rather than a cons, so retrieve the JSXOpeningElement’s
end position from a list.
(js-jsx--context, js-jsx--indenting): New function and variable.
(js-jsx--indentation): New function replacing the prior
js-jsx--indent* functions and js-jsx-indent-line’s implementation.
Use the JSX parsing performed in a JS context to more accurately
calculate JSX indentation than by delegating to sgml-mode functions.
(js--proper-indentation): Use js-jsx--indentation as yet another type
of indentation.
(js-jsx--as-sgml, js-jsx--outermost-enclosing-tag-pos)
(js-jsx--indentation-type, js-jsx--indent-line-in-expression)
(js-jsx--indent-n+1th-line): Remove obsolete functions.
(js-jsx-indent-line): Refactor nearly-obsolete function to behave the
same as it usually would before these changes, without respect to the
binding of js-jsx-syntax.
(js-jsx-mode): Remove obsolete documentation about the use of SGML
variables to control indentation, and don’t bind indent-line-function
any more, because it is no longer necessary given the new
implementation of js-jsx-indent-line.
2019-03-23 14:22:35 -07:00
|
|
|
|
(defun js-jsx--goto-outermost-enclosing-curly (limit)
|
|
|
|
|
"Set point to enclosing “{” at or closest after LIMIT."
|
|
|
|
|
(let (pos)
|
|
|
|
|
(while
|
|
|
|
|
(and
|
|
|
|
|
(setq pos (js-jsx--enclosing-curly-pos))
|
|
|
|
|
(if (>= pos limit) (goto-char pos))
|
|
|
|
|
(> pos limit)))))
|
|
|
|
|
|
2019-03-08 16:29:02 -08:00
|
|
|
|
(defun js-jsx--enclosing-tag-pos ()
|
|
|
|
|
"Return beginning and end of a JSXElement about point.
|
|
|
|
|
Look backward for a JSXElement that both starts before point and
|
|
|
|
|
also ends after point. That may be either a self-closing
|
|
|
|
|
JSXElement or a JSXOpeningElement/JSXClosingElement pair."
|
Indent JSX as parsed in a JS context
Fixes the following issues (and re-fixes indentation issues initially
fixed but later re-broken by previous commits in the process of adding
comprehensive JSX support):
- https://github.com/mooz/js2-mode/issues/389#issuecomment-390766873
- https://github.com/mooz/js2-mode/issues/482
- Bug#32158
- https://github.com/mooz/js2-mode/issues/462
Previously, we delegated to sgml-mode functions for JSX indentation.
However, there were some problems with this approach:
- sgml-mode does not anticipate tags inside attributes when indenting,
which compromises JSX indentation inside JSXExpressionContainers
inside JSXAttributes.
- In previous iterations to provide comprehensive JSX support, it
proved tedious to disambiguate “<” and “>” as JS inequality
operators and arrow functions from opening and closing angle
brackets as part of SGML tags. That code evolved into a more
complete JSX parsing implementation for syntax-propertize rules for
font-locking, discarding the superfluous “<”/“>” disambiguation in
anticipation of using the improved JSX analysis for indentation.
- Using sgml-mode functions, we controlled JSX indentation using SGML
variables. However, JSX is a different thing than SGML; referencing
SGML in JS was a leaky abstraction.
To resolve these issues, use the text properties added by the JSX
syntax-propertize code to determine the boundaries of various aspects
of JSX syntax, and reimplement the sgml-mode indentation code in
js-mode with better respect to JSX indentation conventions.
* lisp/progmodes/js.el (js-jsx-attribute-offset): New variable to
provide a way for users to still control JSX attribute offsets as they
could with sgml-attribute-offset before. The value of this feature is
dubious IMO, but it’s trivial to keep it, so let’s do it just in case.
(js-jsx--goto-outermost-enclosing-curly): New function.
(js-jsx--enclosing-tag-pos): Refactor to be unbounded by curlies, so
this function can be used to find JSXExpressionContainers within JSX.
Fix bug where an enclosing JSXElement couldn’t be found when point was
at the start of its JSXClosingElement. Return the JSXClosingElement’s
position as well, so the JSXClosingElement can be indentified when
indenting and be indented like the matching JSXOpeningElement.
(js-jsx--at-enclosing-tag-child-p): js-jsx--enclosing-tag-pos now
returns a list rather than a cons, so retrieve the JSXOpeningElement’s
end position from a list.
(js-jsx--context, js-jsx--indenting): New function and variable.
(js-jsx--indentation): New function replacing the prior
js-jsx--indent* functions and js-jsx-indent-line’s implementation.
Use the JSX parsing performed in a JS context to more accurately
calculate JSX indentation than by delegating to sgml-mode functions.
(js--proper-indentation): Use js-jsx--indentation as yet another type
of indentation.
(js-jsx--as-sgml, js-jsx--outermost-enclosing-tag-pos)
(js-jsx--indentation-type, js-jsx--indent-line-in-expression)
(js-jsx--indent-n+1th-line): Remove obsolete functions.
(js-jsx-indent-line): Refactor nearly-obsolete function to behave the
same as it usually would before these changes, without respect to the
binding of js-jsx-syntax.
(js-jsx-mode): Remove obsolete documentation about the use of SGML
variables to control indentation, and don’t bind indent-line-function
any more, because it is no longer necessary given the new
implementation of js-jsx-indent-line.
2019-03-23 14:22:35 -07:00
|
|
|
|
(let ((start (point)) tag-beg tag-beg-pos tag-end-pos close-tag-pos)
|
2019-03-08 16:29:02 -08:00
|
|
|
|
(while
|
|
|
|
|
(and
|
|
|
|
|
(setq tag-beg (js--backward-text-property 'js-jsx-tag-beg))
|
|
|
|
|
(progn
|
|
|
|
|
(setq tag-beg-pos (point)
|
|
|
|
|
tag-end-pos (cdr tag-beg))
|
|
|
|
|
(not
|
|
|
|
|
(or
|
|
|
|
|
(and (eq (car tag-beg) 'self-closing)
|
|
|
|
|
(< start tag-end-pos))
|
|
|
|
|
(and (eq (car tag-beg) 'open)
|
Indent JSX as parsed in a JS context
Fixes the following issues (and re-fixes indentation issues initially
fixed but later re-broken by previous commits in the process of adding
comprehensive JSX support):
- https://github.com/mooz/js2-mode/issues/389#issuecomment-390766873
- https://github.com/mooz/js2-mode/issues/482
- Bug#32158
- https://github.com/mooz/js2-mode/issues/462
Previously, we delegated to sgml-mode functions for JSX indentation.
However, there were some problems with this approach:
- sgml-mode does not anticipate tags inside attributes when indenting,
which compromises JSX indentation inside JSXExpressionContainers
inside JSXAttributes.
- In previous iterations to provide comprehensive JSX support, it
proved tedious to disambiguate “<” and “>” as JS inequality
operators and arrow functions from opening and closing angle
brackets as part of SGML tags. That code evolved into a more
complete JSX parsing implementation for syntax-propertize rules for
font-locking, discarding the superfluous “<”/“>” disambiguation in
anticipation of using the improved JSX analysis for indentation.
- Using sgml-mode functions, we controlled JSX indentation using SGML
variables. However, JSX is a different thing than SGML; referencing
SGML in JS was a leaky abstraction.
To resolve these issues, use the text properties added by the JSX
syntax-propertize code to determine the boundaries of various aspects
of JSX syntax, and reimplement the sgml-mode indentation code in
js-mode with better respect to JSX indentation conventions.
* lisp/progmodes/js.el (js-jsx-attribute-offset): New variable to
provide a way for users to still control JSX attribute offsets as they
could with sgml-attribute-offset before. The value of this feature is
dubious IMO, but it’s trivial to keep it, so let’s do it just in case.
(js-jsx--goto-outermost-enclosing-curly): New function.
(js-jsx--enclosing-tag-pos): Refactor to be unbounded by curlies, so
this function can be used to find JSXExpressionContainers within JSX.
Fix bug where an enclosing JSXElement couldn’t be found when point was
at the start of its JSXClosingElement. Return the JSXClosingElement’s
position as well, so the JSXClosingElement can be indentified when
indenting and be indented like the matching JSXOpeningElement.
(js-jsx--at-enclosing-tag-child-p): js-jsx--enclosing-tag-pos now
returns a list rather than a cons, so retrieve the JSXOpeningElement’s
end position from a list.
(js-jsx--context, js-jsx--indenting): New function and variable.
(js-jsx--indentation): New function replacing the prior
js-jsx--indent* functions and js-jsx-indent-line’s implementation.
Use the JSX parsing performed in a JS context to more accurately
calculate JSX indentation than by delegating to sgml-mode functions.
(js--proper-indentation): Use js-jsx--indentation as yet another type
of indentation.
(js-jsx--as-sgml, js-jsx--outermost-enclosing-tag-pos)
(js-jsx--indentation-type, js-jsx--indent-line-in-expression)
(js-jsx--indent-n+1th-line): Remove obsolete functions.
(js-jsx-indent-line): Refactor nearly-obsolete function to behave the
same as it usually would before these changes, without respect to the
binding of js-jsx-syntax.
(js-jsx-mode): Remove obsolete documentation about the use of SGML
variables to control indentation, and don’t bind indent-line-function
any more, because it is no longer necessary given the new
implementation of js-jsx-indent-line.
2019-03-23 14:22:35 -07:00
|
|
|
|
(or (< start tag-end-pos)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char tag-end-pos)
|
|
|
|
|
(setq close-tag-pos (js-jsx--matching-close-tag-pos))
|
|
|
|
|
;; The JSXOpeningElement may be unclosed, else
|
|
|
|
|
;; the closure must occur at/after the start
|
|
|
|
|
;; point (otherwise, a miscellaneous previous
|
|
|
|
|
;; JSXOpeningElement has been found, so keep
|
|
|
|
|
;; looking backwards for an enclosing one).
|
|
|
|
|
(or (not close-tag-pos) (<= start close-tag-pos)))))))))
|
|
|
|
|
;; Don’t return the last tag pos, as it wasn’t enclosing.
|
|
|
|
|
(setq tag-beg nil close-tag-pos nil))
|
|
|
|
|
(and tag-beg (list tag-beg-pos tag-end-pos close-tag-pos))))
|
2019-03-08 16:29:02 -08:00
|
|
|
|
|
|
|
|
|
(defun js-jsx--at-enclosing-tag-child-p ()
|
|
|
|
|
"Return t if point is at an enclosing tag’s child."
|
|
|
|
|
(let ((pos (save-excursion (js-jsx--enclosing-tag-pos))))
|
Indent JSX as parsed in a JS context
Fixes the following issues (and re-fixes indentation issues initially
fixed but later re-broken by previous commits in the process of adding
comprehensive JSX support):
- https://github.com/mooz/js2-mode/issues/389#issuecomment-390766873
- https://github.com/mooz/js2-mode/issues/482
- Bug#32158
- https://github.com/mooz/js2-mode/issues/462
Previously, we delegated to sgml-mode functions for JSX indentation.
However, there were some problems with this approach:
- sgml-mode does not anticipate tags inside attributes when indenting,
which compromises JSX indentation inside JSXExpressionContainers
inside JSXAttributes.
- In previous iterations to provide comprehensive JSX support, it
proved tedious to disambiguate “<” and “>” as JS inequality
operators and arrow functions from opening and closing angle
brackets as part of SGML tags. That code evolved into a more
complete JSX parsing implementation for syntax-propertize rules for
font-locking, discarding the superfluous “<”/“>” disambiguation in
anticipation of using the improved JSX analysis for indentation.
- Using sgml-mode functions, we controlled JSX indentation using SGML
variables. However, JSX is a different thing than SGML; referencing
SGML in JS was a leaky abstraction.
To resolve these issues, use the text properties added by the JSX
syntax-propertize code to determine the boundaries of various aspects
of JSX syntax, and reimplement the sgml-mode indentation code in
js-mode with better respect to JSX indentation conventions.
* lisp/progmodes/js.el (js-jsx-attribute-offset): New variable to
provide a way for users to still control JSX attribute offsets as they
could with sgml-attribute-offset before. The value of this feature is
dubious IMO, but it’s trivial to keep it, so let’s do it just in case.
(js-jsx--goto-outermost-enclosing-curly): New function.
(js-jsx--enclosing-tag-pos): Refactor to be unbounded by curlies, so
this function can be used to find JSXExpressionContainers within JSX.
Fix bug where an enclosing JSXElement couldn’t be found when point was
at the start of its JSXClosingElement. Return the JSXClosingElement’s
position as well, so the JSXClosingElement can be indentified when
indenting and be indented like the matching JSXOpeningElement.
(js-jsx--at-enclosing-tag-child-p): js-jsx--enclosing-tag-pos now
returns a list rather than a cons, so retrieve the JSXOpeningElement’s
end position from a list.
(js-jsx--context, js-jsx--indenting): New function and variable.
(js-jsx--indentation): New function replacing the prior
js-jsx--indent* functions and js-jsx-indent-line’s implementation.
Use the JSX parsing performed in a JS context to more accurately
calculate JSX indentation than by delegating to sgml-mode functions.
(js--proper-indentation): Use js-jsx--indentation as yet another type
of indentation.
(js-jsx--as-sgml, js-jsx--outermost-enclosing-tag-pos)
(js-jsx--indentation-type, js-jsx--indent-line-in-expression)
(js-jsx--indent-n+1th-line): Remove obsolete functions.
(js-jsx-indent-line): Refactor nearly-obsolete function to behave the
same as it usually would before these changes, without respect to the
binding of js-jsx-syntax.
(js-jsx-mode): Remove obsolete documentation about the use of SGML
variables to control indentation, and don’t bind indent-line-function
any more, because it is no longer necessary given the new
implementation of js-jsx-indent-line.
2019-03-23 14:22:35 -07:00
|
|
|
|
(and pos (>= (point) (nth 1 pos)))))
|
2019-03-08 16:29:02 -08:00
|
|
|
|
|
|
|
|
|
(defun js-jsx--text-range (beg end)
|
|
|
|
|
"Identify JSXText within a “>/{/}/<” pair."
|
|
|
|
|
(when (> (- end beg) 0)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char beg)
|
|
|
|
|
(while (and (skip-chars-forward " \t\n" end) (< (point) end))
|
|
|
|
|
;; Comments and string quotes don’t serve their usual
|
|
|
|
|
;; syntactic roles in JSXText; make them plain punctuation to
|
|
|
|
|
;; negate those roles.
|
|
|
|
|
(when (or (= (char-after) ?/) ; comment
|
|
|
|
|
(= (syntax-class (syntax-after (point))) 7)) ; string quote
|
|
|
|
|
(put-text-property (point) (1+ (point)) 'syntax-table '(1)))
|
|
|
|
|
(forward-char)))
|
|
|
|
|
;; Mark JSXText so it can be font-locked as non-keywords.
|
|
|
|
|
(put-text-property beg (1+ beg) 'js-jsx-text (list beg end (current-buffer)))
|
|
|
|
|
;; Ensure future propertization beginning from within the
|
|
|
|
|
;; JSXText determines JSXText context from earlier lines.
|
|
|
|
|
(put-text-property beg end 'syntax-multiline t)))
|
|
|
|
|
|
|
|
|
|
(defun js-jsx--syntax-propertize-tag-text (end)
|
|
|
|
|
"Determine if JSXText is before END and propertize it.
|
|
|
|
|
Text within an open/close tag pair may be JSXText. Temporarily
|
|
|
|
|
interrupt JSXText by JSXExpressionContainers, and terminate
|
|
|
|
|
JSXText when another JSXBoundaryElement is encountered. Despite
|
|
|
|
|
terminations, all JSXText will be identified once all the
|
|
|
|
|
JSXBoundaryElements within an outermost JSXElement’s tree have
|
|
|
|
|
been propertized."
|
|
|
|
|
(let ((text-beg (point))
|
|
|
|
|
forward-sexp-function) ; Use Lisp version.
|
|
|
|
|
(catch 'stop
|
|
|
|
|
(while (re-search-forward "[{<]" end t)
|
|
|
|
|
(js-jsx--text-range text-beg (1- (point)))
|
|
|
|
|
(cond
|
|
|
|
|
((= (char-before) ?{)
|
|
|
|
|
(let (expr-beg expr-end)
|
|
|
|
|
(condition-case nil
|
|
|
|
|
(save-excursion
|
|
|
|
|
(backward-char)
|
|
|
|
|
(setq expr-beg (point))
|
|
|
|
|
(forward-sexp)
|
|
|
|
|
(setq expr-end (point)))
|
|
|
|
|
(scan-error nil))
|
|
|
|
|
;; Recursively propertize the JSXExpressionContainer’s
|
|
|
|
|
;; (possibly-incomplete) expression.
|
|
|
|
|
(js-syntax-propertize (1+ expr-beg) (if expr-end (min (1- expr-end) end) end))
|
|
|
|
|
;; Ensure future propertization beginning from within the
|
|
|
|
|
;; (possibly-incomplete) expression can determine JSXText
|
|
|
|
|
;; context from earlier lines.
|
|
|
|
|
(put-text-property expr-beg (1+ expr-beg) 'js-jsx-expr (or expr-end end)) ; font-lock
|
|
|
|
|
(put-text-property expr-beg (if expr-end (min expr-end end) end) 'syntax-multiline t) ; syntax-propertize
|
|
|
|
|
;; Exit the JSXExpressionContainer if that’s possible,
|
|
|
|
|
;; else move to the end of the propertized area.
|
|
|
|
|
(goto-char (if expr-end (min expr-end end) end))))
|
|
|
|
|
((= (char-before) ?<)
|
|
|
|
|
(backward-char) ; Ensure the next tag can be propertized.
|
|
|
|
|
(throw 'stop nil)))
|
|
|
|
|
(setq text-beg (point))))))
|
|
|
|
|
|
2019-02-17 00:38:01 -08:00
|
|
|
|
(defun js-jsx--syntax-propertize-tag (end)
|
|
|
|
|
"Determine if a JSXBoundaryElement is before END and propertize it.
|
|
|
|
|
Disambiguate JSX from inequality operators and arrow functions by
|
|
|
|
|
testing for syntax only valid as JSX."
|
2019-02-17 21:16:13 -08:00
|
|
|
|
(let ((tag-beg (1- (point))) (type 'open)
|
2019-02-17 00:38:01 -08:00
|
|
|
|
name-beg name-match-data unambiguous
|
|
|
|
|
forward-sexp-function) ; Use Lisp version.
|
|
|
|
|
(catch 'stop
|
|
|
|
|
(while (and (< (point) end)
|
|
|
|
|
(progn (skip-chars-forward " \t\n" end)
|
|
|
|
|
(< (point) end)))
|
|
|
|
|
(cond
|
|
|
|
|
((= (char-after) ?>)
|
|
|
|
|
(forward-char)
|
2019-02-17 21:16:13 -08:00
|
|
|
|
(setq unambiguous t)
|
2019-02-17 00:38:01 -08:00
|
|
|
|
(throw 'stop nil))
|
|
|
|
|
;; Handle a JSXSpreadChild (“<Foo {...bar}”) or a
|
|
|
|
|
;; JSXExpressionContainer as a JSXAttribute value
|
|
|
|
|
;; (“<Foo bar={…}”). Check this early in case continuing a
|
|
|
|
|
;; JSXAttribute parse.
|
|
|
|
|
((and name-beg (= (char-after) ?{))
|
|
|
|
|
(setq unambiguous t) ; JSXExpressionContainer post tag name ⇒ JSX
|
|
|
|
|
(let (expr-end)
|
|
|
|
|
(condition-case nil
|
|
|
|
|
(save-excursion
|
|
|
|
|
(forward-sexp)
|
|
|
|
|
(setq expr-end (point)))
|
|
|
|
|
(scan-error nil))
|
|
|
|
|
(forward-char)
|
|
|
|
|
(if (>= (point) end) (throw 'stop nil))
|
|
|
|
|
(skip-chars-forward " \t\n" end)
|
|
|
|
|
(if (>= (point) end) (throw 'stop nil))
|
|
|
|
|
(if (= (char-after) ?}) (forward-char) ; Shortcut to bail.
|
|
|
|
|
;; Recursively propertize the JSXExpressionContainer’s
|
|
|
|
|
;; expression.
|
|
|
|
|
(js-syntax-propertize (point) (if expr-end (min (1- expr-end) end) end))
|
|
|
|
|
;; Exit the JSXExpressionContainer if that’s possible,
|
|
|
|
|
;; else move to the end of the propertized area.
|
|
|
|
|
(goto-char (if expr-end (min expr-end end) end)))))
|
|
|
|
|
((= (char-after) ?/)
|
|
|
|
|
;; Assume a tag is an open tag until a slash is found, then
|
|
|
|
|
;; figure out what type it actually is.
|
|
|
|
|
(if (eq type 'open) (setq type (if name-beg 'self-closing 'close)))
|
|
|
|
|
(forward-char))
|
|
|
|
|
((looking-at js--dotted-name-re)
|
|
|
|
|
(if (not name-beg)
|
|
|
|
|
(progn
|
|
|
|
|
;; Don’t match code like “if (i < await foo)”
|
|
|
|
|
(if (js--unary-keyword-p (match-string 0)) (throw 'stop nil))
|
|
|
|
|
;; Save boundaries for later fontification after
|
|
|
|
|
;; unambiguously determining the code is JSX.
|
|
|
|
|
(setq name-beg (match-beginning 0)
|
|
|
|
|
name-match-data (match-data))
|
|
|
|
|
(goto-char (match-end 0)))
|
|
|
|
|
(setq unambiguous t) ; Non-unary name followed by 2nd name ⇒ JSX
|
|
|
|
|
;; Save JSXAttribute’s name’s match data for font-locking later.
|
|
|
|
|
(put-text-property (match-beginning 0) (1+ (match-beginning 0))
|
|
|
|
|
'js-jsx-attribute-name (match-data))
|
|
|
|
|
(goto-char (match-end 0))
|
|
|
|
|
(if (>= (point) end) (throw 'stop nil))
|
|
|
|
|
(skip-chars-forward " \t\n" end)
|
|
|
|
|
(if (>= (point) end) (throw 'stop nil))
|
|
|
|
|
;; “=” is optional for null-valued JSXAttributes.
|
|
|
|
|
(when (= (char-after) ?=)
|
|
|
|
|
(forward-char)
|
|
|
|
|
(if (>= (point) end) (throw 'stop nil))
|
|
|
|
|
(skip-chars-forward " \t\n" end)
|
|
|
|
|
(if (>= (point) end) (throw 'stop nil))
|
|
|
|
|
;; Skip over strings (if possible). Any
|
|
|
|
|
;; JSXExpressionContainer here will be parsed in the
|
|
|
|
|
;; next iteration of the loop.
|
|
|
|
|
(when (memq (char-after) '(?\" ?\' ?\`))
|
|
|
|
|
(condition-case nil
|
|
|
|
|
(forward-sexp)
|
|
|
|
|
(scan-error (throw 'stop nil)))))))
|
|
|
|
|
;; There is nothing more to check; this either isn’t JSX, or
|
|
|
|
|
;; the tag is incomplete.
|
|
|
|
|
(t (throw 'stop nil)))))
|
|
|
|
|
(when unambiguous
|
|
|
|
|
;; Save JSXBoundaryElement’s name’s match data for font-locking.
|
|
|
|
|
(if name-beg (put-text-property name-beg (1+ name-beg) 'js-jsx-tag-name name-match-data))
|
2019-03-08 16:29:02 -08:00
|
|
|
|
;; Mark beginning and end of tag for font-locking.
|
2019-02-17 21:16:13 -08:00
|
|
|
|
(put-text-property tag-beg (1+ tag-beg) 'js-jsx-tag-beg (cons type (point)))
|
2019-03-08 16:29:02 -08:00
|
|
|
|
(put-text-property (point) (1+ (point)) 'js-jsx-tag-end tag-beg))
|
|
|
|
|
(if (js-jsx--at-enclosing-tag-child-p) (js-jsx--syntax-propertize-tag-text end))))
|
2019-02-17 00:38:01 -08:00
|
|
|
|
|
|
|
|
|
(defconst js-jsx--text-properties
|
2019-03-08 16:29:02 -08:00
|
|
|
|
(list
|
|
|
|
|
'js-jsx-tag-beg nil 'js-jsx-tag-end nil
|
|
|
|
|
'js-jsx-tag-name nil 'js-jsx-attribute-name nil
|
|
|
|
|
'js-jsx-text nil 'js-jsx-expr nil)
|
2019-02-17 00:38:01 -08:00
|
|
|
|
"Plist of text properties added by `js-syntax-propertize'.")
|
2019-02-11 03:00:34 -08:00
|
|
|
|
|
2011-08-12 11:32:39 -04:00
|
|
|
|
(defun js-syntax-propertize (start end)
|
2017-01-29 10:39:55 +02:00
|
|
|
|
;; JavaScript allows immediate regular expression objects, written /.../.
|
2011-08-12 11:32:39 -04:00
|
|
|
|
(goto-char start)
|
2019-02-17 00:38:01 -08:00
|
|
|
|
(if js-jsx-syntax (remove-text-properties start end js-jsx--text-properties))
|
2011-08-12 11:32:39 -04:00
|
|
|
|
(js-syntax-propertize-regexp end)
|
|
|
|
|
(funcall
|
|
|
|
|
(syntax-propertize-rules
|
|
|
|
|
;; Distinguish /-division from /-regexp chars (and from /-comment-starter).
|
2012-05-25 11:03:22 -04:00
|
|
|
|
;; FIXME: Allow regexps after infix ops like + ...
|
|
|
|
|
;; https://developer.mozilla.org/en/JavaScript/Reference/Operators
|
2017-01-16 14:02:45 -07:00
|
|
|
|
;; We can probably just add +, -, <, >, %, ^, ~, ?, : at which
|
2012-05-25 11:03:22 -04:00
|
|
|
|
;; point I think only * and / would be missing which could also be added,
|
|
|
|
|
;; but need care to avoid affecting the // and */ comment markers.
|
2017-01-16 14:02:45 -07:00
|
|
|
|
("\\(?:^\\|[=([{,:;|&!]\\|\\_<return\\_>\\)\\(?:[ \t]\\)*\\(/\\)[^/*]"
|
2011-08-12 11:32:39 -04:00
|
|
|
|
(1 (ignore
|
|
|
|
|
(forward-char -1)
|
|
|
|
|
(when (or (not (memq (char-after (match-beginning 0)) '(?\s ?\t)))
|
|
|
|
|
;; If the / is at the beginning of line, we have to check
|
|
|
|
|
;; the end of the previous text.
|
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char (match-beginning 0))
|
|
|
|
|
(forward-comment (- (point)))
|
|
|
|
|
(memq (char-before)
|
|
|
|
|
(eval-when-compile (append "=({[,:;" '(nil))))))
|
|
|
|
|
(put-text-property (match-beginning 1) (match-end 1)
|
|
|
|
|
'syntax-table (string-to-syntax "\"/"))
|
2016-05-04 08:53:00 -04:00
|
|
|
|
(js-syntax-propertize-regexp end)))))
|
2019-02-17 00:38:01 -08:00
|
|
|
|
("\\`\\(#\\)!" (1 "< b"))
|
|
|
|
|
("<" (0 (ignore (if js-jsx-syntax (js-jsx--syntax-propertize-tag end))))))
|
|
|
|
|
(point) end))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
2015-09-27 10:04:09 +02:00
|
|
|
|
(defconst js--prettify-symbols-alist
|
|
|
|
|
'(("=>" . ?⇒)
|
|
|
|
|
(">=" . ?≥)
|
|
|
|
|
("<=" . ?≤))
|
|
|
|
|
"Alist of symbol prettifications for JavaScript.")
|
|
|
|
|
|
2009-08-14 23:02:38 +00:00
|
|
|
|
;;; Indentation
|
|
|
|
|
|
|
|
|
|
(defconst js--possibly-braceless-keyword-re
|
|
|
|
|
(js--regexp-opt-symbol
|
|
|
|
|
'("catch" "do" "else" "finally" "for" "if" "try" "while" "with"
|
|
|
|
|
"each"))
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Regexp matching keywords optionally followed by an opening brace.")
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
2013-01-11 18:24:52 -05:00
|
|
|
|
(defconst js--declaration-keyword-re
|
|
|
|
|
(regexp-opt '("var" "let" "const") 'words)
|
|
|
|
|
"Regular expression matching variable declaration keywords.")
|
|
|
|
|
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(defconst js--indent-operator-re
|
2016-05-11 02:26:54 +03:00
|
|
|
|
(concat "[-+*/%<>&^|?:.]\\([^-+*/.]\\|$\\)\\|!?=\\|"
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(js--regexp-opt-symbol '("in" "instanceof")))
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Regexp matching operators that affect indentation of continued expressions.")
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
2019-02-15 22:15:11 -08:00
|
|
|
|
(defun js-jsx--looking-at-start-tag-p ()
|
Refactor JSX indentation code to improve enclosing JSX discovery
Fix a number of bugs reported for JSX indentation (caused by poor JSX
detection):
- https://github.com/mooz/js2-mode/issues/140#issuecomment-166250016
- https://github.com/mooz/js2-mode/issues/490
- Bug#24896 / https://github.com/mooz/js2-mode/issues/389 (with
respect to comments)
- Bug#26001 /
https://github.com/mooz/js2-mode/issues/389#issuecomment-271869380
- https://github.com/mooz/js2-mode/issues/411 / Bug#27000 /
https://github.com/mooz/js2-mode/issues/451
Potentially manifest some new bugs (due to false positives with ‘<’
and ‘>’ and SGML detection). Slow down indentation a fair bit.
* list/progmodes/js.el (js-jsx-syntax, js--jsx-start-tag-re)
(js--looking-at-jsx-start-tag-p, js--looking-back-at-jsx-end-tag-p):
New variables and functions.
(js--jsx-find-before-tag, js--jsx-after-tag-re): Deleted.
(js--looking-at-operator-p): Don’t mistake a JSXOpeningElement for the
‘<’ operator.
(js--continued-expression-p): Don’t mistake a JSXClosingElement as a
fragment of a continued expression including the ‘>’ operator.
(js--as-sgml): Simplify. Probably needn’t bind forward-sexp-function
to nil (sgml-mode already does) and probably shouldn’t bind
parse-sexp-lookup-properties to nil either (see Bug#24896).
(js--outermost-enclosing-jsx-tag-pos): Find enclosing JSX more
accurately than js--jsx-find-before-tag. Use sgml-mode’s parsing
logic, rather than unreliable heuristics like paren-wrapping. This
implementation is much slower; the previous implementation was fast,
but at the expense of accuracy. To make up for all the grief we’ve
caused users, we will prefer accuracy over speed from now on. That
said, this can still probably be optimized a lot.
(js--jsx-indented-element-p): Rename to js--jsx-indentation, since it
doesn’t just return a boolean.
(js--jsx-indentation): Refactor js--jsx-indented-element-p to simplify
the implementation as the improved accuracy of other code allows (and
to repent for some awful stylistic choices I made earlier).
(js--expression-in-sgml-indent-line): Rename to
js--indent-line-in-jsx-expression, since it’s a private function and
we can give it a name that reads more like English.
(js--indent-line-in-jsx-expression): Restructure point adjustment
logic more like js-indent-line.
(js--indent-n+1th-jsx-line): New function to complement
js--indent-line-in-jsx-expression.
(js-jsx-indent-line): Refactor. Don’t bind js--continued-expression-p
to ignore any more; instead, rely on the improved accuracy of
js--continued-expression-p.
(js-jsx-mode): Set js-jsx-syntax to t. For now, this will be the flag
we use to determine whether ‘JSX is enabled.’ (Maybe later, we will
refactor the code to use this variable instead of requiring
js-jsx-mode to be enabled, thus rendering the mode obsolete.)
2019-02-09 20:06:29 -08:00
|
|
|
|
"Non-nil if a JSXOpeningElement immediately follows point."
|
2019-03-23 15:01:55 -07:00
|
|
|
|
(let ((tag-beg (get-text-property (point) 'js-jsx-tag-beg)))
|
|
|
|
|
(and tag-beg (memq (car tag-beg) '(open self-closing)))))
|
Refactor JSX indentation code to improve enclosing JSX discovery
Fix a number of bugs reported for JSX indentation (caused by poor JSX
detection):
- https://github.com/mooz/js2-mode/issues/140#issuecomment-166250016
- https://github.com/mooz/js2-mode/issues/490
- Bug#24896 / https://github.com/mooz/js2-mode/issues/389 (with
respect to comments)
- Bug#26001 /
https://github.com/mooz/js2-mode/issues/389#issuecomment-271869380
- https://github.com/mooz/js2-mode/issues/411 / Bug#27000 /
https://github.com/mooz/js2-mode/issues/451
Potentially manifest some new bugs (due to false positives with ‘<’
and ‘>’ and SGML detection). Slow down indentation a fair bit.
* list/progmodes/js.el (js-jsx-syntax, js--jsx-start-tag-re)
(js--looking-at-jsx-start-tag-p, js--looking-back-at-jsx-end-tag-p):
New variables and functions.
(js--jsx-find-before-tag, js--jsx-after-tag-re): Deleted.
(js--looking-at-operator-p): Don’t mistake a JSXOpeningElement for the
‘<’ operator.
(js--continued-expression-p): Don’t mistake a JSXClosingElement as a
fragment of a continued expression including the ‘>’ operator.
(js--as-sgml): Simplify. Probably needn’t bind forward-sexp-function
to nil (sgml-mode already does) and probably shouldn’t bind
parse-sexp-lookup-properties to nil either (see Bug#24896).
(js--outermost-enclosing-jsx-tag-pos): Find enclosing JSX more
accurately than js--jsx-find-before-tag. Use sgml-mode’s parsing
logic, rather than unreliable heuristics like paren-wrapping. This
implementation is much slower; the previous implementation was fast,
but at the expense of accuracy. To make up for all the grief we’ve
caused users, we will prefer accuracy over speed from now on. That
said, this can still probably be optimized a lot.
(js--jsx-indented-element-p): Rename to js--jsx-indentation, since it
doesn’t just return a boolean.
(js--jsx-indentation): Refactor js--jsx-indented-element-p to simplify
the implementation as the improved accuracy of other code allows (and
to repent for some awful stylistic choices I made earlier).
(js--expression-in-sgml-indent-line): Rename to
js--indent-line-in-jsx-expression, since it’s a private function and
we can give it a name that reads more like English.
(js--indent-line-in-jsx-expression): Restructure point adjustment
logic more like js-indent-line.
(js--indent-n+1th-jsx-line): New function to complement
js--indent-line-in-jsx-expression.
(js-jsx-indent-line): Refactor. Don’t bind js--continued-expression-p
to ignore any more; instead, rely on the improved accuracy of
js--continued-expression-p.
(js-jsx-mode): Set js-jsx-syntax to t. For now, this will be the flag
we use to determine whether ‘JSX is enabled.’ (Maybe later, we will
refactor the code to use this variable instead of requiring
js-jsx-mode to be enabled, thus rendering the mode obsolete.)
2019-02-09 20:06:29 -08:00
|
|
|
|
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(defun js--looking-at-operator-p ()
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Return non-nil if point is on a JavaScript operator, other than a comma."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(save-match-data
|
|
|
|
|
(and (looking-at js--indent-operator-re)
|
2015-10-15 22:34:18 +03:00
|
|
|
|
(or (not (eq (char-after) ?:))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(save-excursion
|
2017-04-13 03:50:41 +03:00
|
|
|
|
(js--backward-syntactic-ws)
|
|
|
|
|
(when (= (char-before) ?\)) (backward-list))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(and (js--re-search-backward "[?:{]\\|\\_<case\\_>" nil t)
|
2015-10-15 22:34:18 +03:00
|
|
|
|
(eq (char-after) ??))))
|
2016-11-17 01:58:59 +02:00
|
|
|
|
(not (and
|
|
|
|
|
(eq (char-after) ?/)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(eq (nth 3 (syntax-ppss)) ?/))))
|
2015-10-15 22:34:18 +03:00
|
|
|
|
(not (and
|
|
|
|
|
(eq (char-after) ?*)
|
2016-03-05 14:35:10 +02:00
|
|
|
|
;; Generator method (possibly using computed property).
|
|
|
|
|
(looking-at (concat "\\* *\\(?:\\[\\|" js--name-re " *(\\)"))
|
2015-10-15 22:34:18 +03:00
|
|
|
|
(save-excursion
|
2016-03-05 14:35:10 +02:00
|
|
|
|
(js--backward-syntactic-ws)
|
|
|
|
|
;; We might misindent some expressions that would
|
|
|
|
|
;; return NaN anyway. Shouldn't be a problem.
|
Refactor JSX indentation code to improve enclosing JSX discovery
Fix a number of bugs reported for JSX indentation (caused by poor JSX
detection):
- https://github.com/mooz/js2-mode/issues/140#issuecomment-166250016
- https://github.com/mooz/js2-mode/issues/490
- Bug#24896 / https://github.com/mooz/js2-mode/issues/389 (with
respect to comments)
- Bug#26001 /
https://github.com/mooz/js2-mode/issues/389#issuecomment-271869380
- https://github.com/mooz/js2-mode/issues/411 / Bug#27000 /
https://github.com/mooz/js2-mode/issues/451
Potentially manifest some new bugs (due to false positives with ‘<’
and ‘>’ and SGML detection). Slow down indentation a fair bit.
* list/progmodes/js.el (js-jsx-syntax, js--jsx-start-tag-re)
(js--looking-at-jsx-start-tag-p, js--looking-back-at-jsx-end-tag-p):
New variables and functions.
(js--jsx-find-before-tag, js--jsx-after-tag-re): Deleted.
(js--looking-at-operator-p): Don’t mistake a JSXOpeningElement for the
‘<’ operator.
(js--continued-expression-p): Don’t mistake a JSXClosingElement as a
fragment of a continued expression including the ‘>’ operator.
(js--as-sgml): Simplify. Probably needn’t bind forward-sexp-function
to nil (sgml-mode already does) and probably shouldn’t bind
parse-sexp-lookup-properties to nil either (see Bug#24896).
(js--outermost-enclosing-jsx-tag-pos): Find enclosing JSX more
accurately than js--jsx-find-before-tag. Use sgml-mode’s parsing
logic, rather than unreliable heuristics like paren-wrapping. This
implementation is much slower; the previous implementation was fast,
but at the expense of accuracy. To make up for all the grief we’ve
caused users, we will prefer accuracy over speed from now on. That
said, this can still probably be optimized a lot.
(js--jsx-indented-element-p): Rename to js--jsx-indentation, since it
doesn’t just return a boolean.
(js--jsx-indentation): Refactor js--jsx-indented-element-p to simplify
the implementation as the improved accuracy of other code allows (and
to repent for some awful stylistic choices I made earlier).
(js--expression-in-sgml-indent-line): Rename to
js--indent-line-in-jsx-expression, since it’s a private function and
we can give it a name that reads more like English.
(js--indent-line-in-jsx-expression): Restructure point adjustment
logic more like js-indent-line.
(js--indent-n+1th-jsx-line): New function to complement
js--indent-line-in-jsx-expression.
(js-jsx-indent-line): Refactor. Don’t bind js--continued-expression-p
to ignore any more; instead, rely on the improved accuracy of
js--continued-expression-p.
(js-jsx-mode): Set js-jsx-syntax to t. For now, this will be the flag
we use to determine whether ‘JSX is enabled.’ (Maybe later, we will
refactor the code to use this variable instead of requiring
js-jsx-mode to be enabled, thus rendering the mode obsolete.)
2019-02-09 20:06:29 -08:00
|
|
|
|
(memq (char-before) '(?, ?} ?{)))))
|
|
|
|
|
;; “<” isn’t necessarily an operator in JSX.
|
2019-02-15 22:15:11 -08:00
|
|
|
|
(not (and js-jsx-syntax (js-jsx--looking-at-start-tag-p))))))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
2017-01-09 22:15:57 -07:00
|
|
|
|
(defun js--find-newline-backward ()
|
|
|
|
|
"Move backward to the nearest newline that is not in a block comment."
|
|
|
|
|
(let ((continue t)
|
|
|
|
|
(result t))
|
|
|
|
|
(while continue
|
|
|
|
|
(setq continue nil)
|
|
|
|
|
(if (search-backward "\n" nil t)
|
|
|
|
|
(let ((parse (syntax-ppss)))
|
|
|
|
|
;; We match the end of a // comment but not a newline in a
|
|
|
|
|
;; block comment.
|
|
|
|
|
(when (nth 4 parse)
|
|
|
|
|
(goto-char (nth 8 parse))
|
|
|
|
|
;; If we saw a block comment, keep trying.
|
|
|
|
|
(unless (nth 7 parse)
|
|
|
|
|
(setq continue t))))
|
|
|
|
|
(setq result nil)))
|
|
|
|
|
result))
|
|
|
|
|
|
2019-02-15 22:15:11 -08:00
|
|
|
|
(defun js-jsx--looking-back-at-end-tag-p ()
|
Refactor JSX indentation code to improve enclosing JSX discovery
Fix a number of bugs reported for JSX indentation (caused by poor JSX
detection):
- https://github.com/mooz/js2-mode/issues/140#issuecomment-166250016
- https://github.com/mooz/js2-mode/issues/490
- Bug#24896 / https://github.com/mooz/js2-mode/issues/389 (with
respect to comments)
- Bug#26001 /
https://github.com/mooz/js2-mode/issues/389#issuecomment-271869380
- https://github.com/mooz/js2-mode/issues/411 / Bug#27000 /
https://github.com/mooz/js2-mode/issues/451
Potentially manifest some new bugs (due to false positives with ‘<’
and ‘>’ and SGML detection). Slow down indentation a fair bit.
* list/progmodes/js.el (js-jsx-syntax, js--jsx-start-tag-re)
(js--looking-at-jsx-start-tag-p, js--looking-back-at-jsx-end-tag-p):
New variables and functions.
(js--jsx-find-before-tag, js--jsx-after-tag-re): Deleted.
(js--looking-at-operator-p): Don’t mistake a JSXOpeningElement for the
‘<’ operator.
(js--continued-expression-p): Don’t mistake a JSXClosingElement as a
fragment of a continued expression including the ‘>’ operator.
(js--as-sgml): Simplify. Probably needn’t bind forward-sexp-function
to nil (sgml-mode already does) and probably shouldn’t bind
parse-sexp-lookup-properties to nil either (see Bug#24896).
(js--outermost-enclosing-jsx-tag-pos): Find enclosing JSX more
accurately than js--jsx-find-before-tag. Use sgml-mode’s parsing
logic, rather than unreliable heuristics like paren-wrapping. This
implementation is much slower; the previous implementation was fast,
but at the expense of accuracy. To make up for all the grief we’ve
caused users, we will prefer accuracy over speed from now on. That
said, this can still probably be optimized a lot.
(js--jsx-indented-element-p): Rename to js--jsx-indentation, since it
doesn’t just return a boolean.
(js--jsx-indentation): Refactor js--jsx-indented-element-p to simplify
the implementation as the improved accuracy of other code allows (and
to repent for some awful stylistic choices I made earlier).
(js--expression-in-sgml-indent-line): Rename to
js--indent-line-in-jsx-expression, since it’s a private function and
we can give it a name that reads more like English.
(js--indent-line-in-jsx-expression): Restructure point adjustment
logic more like js-indent-line.
(js--indent-n+1th-jsx-line): New function to complement
js--indent-line-in-jsx-expression.
(js-jsx-indent-line): Refactor. Don’t bind js--continued-expression-p
to ignore any more; instead, rely on the improved accuracy of
js--continued-expression-p.
(js-jsx-mode): Set js-jsx-syntax to t. For now, this will be the flag
we use to determine whether ‘JSX is enabled.’ (Maybe later, we will
refactor the code to use this variable instead of requiring
js-jsx-mode to be enabled, thus rendering the mode obsolete.)
2019-02-09 20:06:29 -08:00
|
|
|
|
"Non-nil if a JSXClosingElement immediately precedes point."
|
2019-03-23 15:01:55 -07:00
|
|
|
|
(get-text-property (point) 'js-jsx-tag-end))
|
Refactor JSX indentation code to improve enclosing JSX discovery
Fix a number of bugs reported for JSX indentation (caused by poor JSX
detection):
- https://github.com/mooz/js2-mode/issues/140#issuecomment-166250016
- https://github.com/mooz/js2-mode/issues/490
- Bug#24896 / https://github.com/mooz/js2-mode/issues/389 (with
respect to comments)
- Bug#26001 /
https://github.com/mooz/js2-mode/issues/389#issuecomment-271869380
- https://github.com/mooz/js2-mode/issues/411 / Bug#27000 /
https://github.com/mooz/js2-mode/issues/451
Potentially manifest some new bugs (due to false positives with ‘<’
and ‘>’ and SGML detection). Slow down indentation a fair bit.
* list/progmodes/js.el (js-jsx-syntax, js--jsx-start-tag-re)
(js--looking-at-jsx-start-tag-p, js--looking-back-at-jsx-end-tag-p):
New variables and functions.
(js--jsx-find-before-tag, js--jsx-after-tag-re): Deleted.
(js--looking-at-operator-p): Don’t mistake a JSXOpeningElement for the
‘<’ operator.
(js--continued-expression-p): Don’t mistake a JSXClosingElement as a
fragment of a continued expression including the ‘>’ operator.
(js--as-sgml): Simplify. Probably needn’t bind forward-sexp-function
to nil (sgml-mode already does) and probably shouldn’t bind
parse-sexp-lookup-properties to nil either (see Bug#24896).
(js--outermost-enclosing-jsx-tag-pos): Find enclosing JSX more
accurately than js--jsx-find-before-tag. Use sgml-mode’s parsing
logic, rather than unreliable heuristics like paren-wrapping. This
implementation is much slower; the previous implementation was fast,
but at the expense of accuracy. To make up for all the grief we’ve
caused users, we will prefer accuracy over speed from now on. That
said, this can still probably be optimized a lot.
(js--jsx-indented-element-p): Rename to js--jsx-indentation, since it
doesn’t just return a boolean.
(js--jsx-indentation): Refactor js--jsx-indented-element-p to simplify
the implementation as the improved accuracy of other code allows (and
to repent for some awful stylistic choices I made earlier).
(js--expression-in-sgml-indent-line): Rename to
js--indent-line-in-jsx-expression, since it’s a private function and
we can give it a name that reads more like English.
(js--indent-line-in-jsx-expression): Restructure point adjustment
logic more like js-indent-line.
(js--indent-n+1th-jsx-line): New function to complement
js--indent-line-in-jsx-expression.
(js-jsx-indent-line): Refactor. Don’t bind js--continued-expression-p
to ignore any more; instead, rely on the improved accuracy of
js--continued-expression-p.
(js-jsx-mode): Set js-jsx-syntax to t. For now, this will be the flag
we use to determine whether ‘JSX is enabled.’ (Maybe later, we will
refactor the code to use this variable instead of requiring
js-jsx-mode to be enabled, thus rendering the mode obsolete.)
2019-02-09 20:06:29 -08:00
|
|
|
|
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(defun js--continued-expression-p ()
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Return non-nil if the current line continues an expression."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(save-excursion
|
|
|
|
|
(back-to-indentation)
|
2016-04-02 03:02:03 +03:00
|
|
|
|
(if (js--looking-at-operator-p)
|
2017-10-26 02:43:33 +03:00
|
|
|
|
(if (eq (char-after) ?/)
|
|
|
|
|
(prog1
|
|
|
|
|
(not (nth 3 (syntax-ppss (1+ (point)))))
|
|
|
|
|
(forward-char -1))
|
|
|
|
|
(or
|
|
|
|
|
(not (memq (char-after) '(?- ?+)))
|
|
|
|
|
(progn
|
|
|
|
|
(forward-comment (- (point)))
|
|
|
|
|
(not (memq (char-before) '(?, ?\[ ?\())))))
|
2017-01-09 22:15:57 -07:00
|
|
|
|
(and (js--find-newline-backward)
|
2016-04-02 03:02:03 +03:00
|
|
|
|
(progn
|
|
|
|
|
(skip-chars-backward " \t")
|
Refactor JSX indentation code to improve enclosing JSX discovery
Fix a number of bugs reported for JSX indentation (caused by poor JSX
detection):
- https://github.com/mooz/js2-mode/issues/140#issuecomment-166250016
- https://github.com/mooz/js2-mode/issues/490
- Bug#24896 / https://github.com/mooz/js2-mode/issues/389 (with
respect to comments)
- Bug#26001 /
https://github.com/mooz/js2-mode/issues/389#issuecomment-271869380
- https://github.com/mooz/js2-mode/issues/411 / Bug#27000 /
https://github.com/mooz/js2-mode/issues/451
Potentially manifest some new bugs (due to false positives with ‘<’
and ‘>’ and SGML detection). Slow down indentation a fair bit.
* list/progmodes/js.el (js-jsx-syntax, js--jsx-start-tag-re)
(js--looking-at-jsx-start-tag-p, js--looking-back-at-jsx-end-tag-p):
New variables and functions.
(js--jsx-find-before-tag, js--jsx-after-tag-re): Deleted.
(js--looking-at-operator-p): Don’t mistake a JSXOpeningElement for the
‘<’ operator.
(js--continued-expression-p): Don’t mistake a JSXClosingElement as a
fragment of a continued expression including the ‘>’ operator.
(js--as-sgml): Simplify. Probably needn’t bind forward-sexp-function
to nil (sgml-mode already does) and probably shouldn’t bind
parse-sexp-lookup-properties to nil either (see Bug#24896).
(js--outermost-enclosing-jsx-tag-pos): Find enclosing JSX more
accurately than js--jsx-find-before-tag. Use sgml-mode’s parsing
logic, rather than unreliable heuristics like paren-wrapping. This
implementation is much slower; the previous implementation was fast,
but at the expense of accuracy. To make up for all the grief we’ve
caused users, we will prefer accuracy over speed from now on. That
said, this can still probably be optimized a lot.
(js--jsx-indented-element-p): Rename to js--jsx-indentation, since it
doesn’t just return a boolean.
(js--jsx-indentation): Refactor js--jsx-indented-element-p to simplify
the implementation as the improved accuracy of other code allows (and
to repent for some awful stylistic choices I made earlier).
(js--expression-in-sgml-indent-line): Rename to
js--indent-line-in-jsx-expression, since it’s a private function and
we can give it a name that reads more like English.
(js--indent-line-in-jsx-expression): Restructure point adjustment
logic more like js-indent-line.
(js--indent-n+1th-jsx-line): New function to complement
js--indent-line-in-jsx-expression.
(js-jsx-indent-line): Refactor. Don’t bind js--continued-expression-p
to ignore any more; instead, rely on the improved accuracy of
js--continued-expression-p.
(js-jsx-mode): Set js-jsx-syntax to t. For now, this will be the flag
we use to determine whether ‘JSX is enabled.’ (Maybe later, we will
refactor the code to use this variable instead of requiring
js-jsx-mode to be enabled, thus rendering the mode obsolete.)
2019-02-09 20:06:29 -08:00
|
|
|
|
(and
|
|
|
|
|
;; The “>” at the end of any JSXBoundaryElement isn’t
|
|
|
|
|
;; part of a continued expression.
|
2019-02-15 22:15:11 -08:00
|
|
|
|
(not (and js-jsx-syntax (js-jsx--looking-back-at-end-tag-p)))
|
Refactor JSX indentation code to improve enclosing JSX discovery
Fix a number of bugs reported for JSX indentation (caused by poor JSX
detection):
- https://github.com/mooz/js2-mode/issues/140#issuecomment-166250016
- https://github.com/mooz/js2-mode/issues/490
- Bug#24896 / https://github.com/mooz/js2-mode/issues/389 (with
respect to comments)
- Bug#26001 /
https://github.com/mooz/js2-mode/issues/389#issuecomment-271869380
- https://github.com/mooz/js2-mode/issues/411 / Bug#27000 /
https://github.com/mooz/js2-mode/issues/451
Potentially manifest some new bugs (due to false positives with ‘<’
and ‘>’ and SGML detection). Slow down indentation a fair bit.
* list/progmodes/js.el (js-jsx-syntax, js--jsx-start-tag-re)
(js--looking-at-jsx-start-tag-p, js--looking-back-at-jsx-end-tag-p):
New variables and functions.
(js--jsx-find-before-tag, js--jsx-after-tag-re): Deleted.
(js--looking-at-operator-p): Don’t mistake a JSXOpeningElement for the
‘<’ operator.
(js--continued-expression-p): Don’t mistake a JSXClosingElement as a
fragment of a continued expression including the ‘>’ operator.
(js--as-sgml): Simplify. Probably needn’t bind forward-sexp-function
to nil (sgml-mode already does) and probably shouldn’t bind
parse-sexp-lookup-properties to nil either (see Bug#24896).
(js--outermost-enclosing-jsx-tag-pos): Find enclosing JSX more
accurately than js--jsx-find-before-tag. Use sgml-mode’s parsing
logic, rather than unreliable heuristics like paren-wrapping. This
implementation is much slower; the previous implementation was fast,
but at the expense of accuracy. To make up for all the grief we’ve
caused users, we will prefer accuracy over speed from now on. That
said, this can still probably be optimized a lot.
(js--jsx-indented-element-p): Rename to js--jsx-indentation, since it
doesn’t just return a boolean.
(js--jsx-indentation): Refactor js--jsx-indented-element-p to simplify
the implementation as the improved accuracy of other code allows (and
to repent for some awful stylistic choices I made earlier).
(js--expression-in-sgml-indent-line): Rename to
js--indent-line-in-jsx-expression, since it’s a private function and
we can give it a name that reads more like English.
(js--indent-line-in-jsx-expression): Restructure point adjustment
logic more like js-indent-line.
(js--indent-n+1th-jsx-line): New function to complement
js--indent-line-in-jsx-expression.
(js-jsx-indent-line): Refactor. Don’t bind js--continued-expression-p
to ignore any more; instead, rely on the improved accuracy of
js--continued-expression-p.
(js-jsx-mode): Set js-jsx-syntax to t. For now, this will be the flag
we use to determine whether ‘JSX is enabled.’ (Maybe later, we will
refactor the code to use this variable instead of requiring
js-jsx-mode to be enabled, thus rendering the mode obsolete.)
2019-02-09 20:06:29 -08:00
|
|
|
|
(progn
|
|
|
|
|
(or (bobp) (backward-char))
|
|
|
|
|
(and (> (point) (point-min))
|
|
|
|
|
(save-excursion
|
|
|
|
|
(backward-char)
|
|
|
|
|
(not (looking-at "[/*]/\\|=>")))
|
|
|
|
|
(js--looking-at-operator-p)
|
|
|
|
|
(and (progn (backward-char)
|
|
|
|
|
(not (looking-at "\\+\\+\\|--\\|/[/*]"))))))))))))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
2017-01-12 23:15:00 -07:00
|
|
|
|
(defun js--skip-term-backward ()
|
|
|
|
|
"Skip a term before point; return t if a term was skipped."
|
|
|
|
|
(let ((term-skipped nil))
|
|
|
|
|
;; Skip backward over balanced parens.
|
|
|
|
|
(let ((progress t))
|
|
|
|
|
(while progress
|
|
|
|
|
(setq progress nil)
|
|
|
|
|
;; First skip whitespace.
|
|
|
|
|
(skip-syntax-backward " ")
|
|
|
|
|
;; Now if we're looking at closing paren, skip to the opener.
|
|
|
|
|
;; This doesn't strictly follow JS syntax, in that we might
|
|
|
|
|
;; skip something nonsensical like "()[]{}", but it is enough
|
|
|
|
|
;; if it works ok for valid input.
|
|
|
|
|
(when (memq (char-before) '(?\] ?\) ?\}))
|
|
|
|
|
(setq progress t term-skipped t)
|
|
|
|
|
(backward-list))))
|
|
|
|
|
;; Maybe skip over a symbol.
|
|
|
|
|
(let ((save-point (point)))
|
|
|
|
|
(if (and (< (skip-syntax-backward "w_") 0)
|
|
|
|
|
(looking-at js--name-re))
|
|
|
|
|
;; Skipped.
|
|
|
|
|
(progn
|
|
|
|
|
(setq term-skipped t)
|
|
|
|
|
(skip-syntax-backward " "))
|
|
|
|
|
;; Did not skip, so restore point.
|
|
|
|
|
(goto-char save-point)))
|
|
|
|
|
(when (and term-skipped (> (point) (point-min)))
|
|
|
|
|
(backward-char)
|
|
|
|
|
(eq (char-after) ?.))))
|
|
|
|
|
|
|
|
|
|
(defun js--skip-terms-backward ()
|
|
|
|
|
"Skip any number of terms backward.
|
|
|
|
|
Move point to the earliest \".\" without changing paren levels.
|
|
|
|
|
Returns t if successful, nil if no term was found."
|
|
|
|
|
(when (js--skip-term-backward)
|
|
|
|
|
;; Found at least one.
|
|
|
|
|
(let ((last-point (point)))
|
|
|
|
|
(while (js--skip-term-backward)
|
|
|
|
|
(setq last-point (point)))
|
|
|
|
|
(goto-char last-point)
|
|
|
|
|
t)))
|
|
|
|
|
|
|
|
|
|
(defun js--chained-expression-p ()
|
|
|
|
|
"A helper for js--proper-indentation that handles chained expressions.
|
|
|
|
|
A chained expression is when the current line starts with '.' and the
|
|
|
|
|
previous line also has a '.' expression.
|
|
|
|
|
This function returns the indentation for the current line if it is
|
|
|
|
|
a chained expression line; otherwise nil.
|
|
|
|
|
This should only be called while point is at the start of the line's content,
|
|
|
|
|
as determined by `back-to-indentation'."
|
|
|
|
|
(when js-chain-indent
|
|
|
|
|
(save-excursion
|
|
|
|
|
(when (and (eq (char-after) ?.)
|
|
|
|
|
(js--continued-expression-p)
|
|
|
|
|
(js--find-newline-backward)
|
|
|
|
|
(js--skip-terms-backward))
|
|
|
|
|
(current-column)))))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defun js--end-of-do-while-loop-p ()
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Return non-nil if point is on the \"while\" of a do-while statement.
|
|
|
|
|
Otherwise, return nil. A braceless do-while statement spanning
|
|
|
|
|
several lines requires that the start of the loop is indented to
|
|
|
|
|
the same column as the current line."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(interactive)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(save-match-data
|
|
|
|
|
(when (looking-at "\\s-*\\_<while\\_>")
|
|
|
|
|
(if (save-excursion
|
2019-03-19 18:45:17 -07:00
|
|
|
|
(skip-chars-backward " \t\n}")
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(looking-at "[ \t\n]*}"))
|
|
|
|
|
(save-excursion
|
|
|
|
|
(backward-list) (forward-symbol -1) (looking-at "\\_<do\\_>"))
|
|
|
|
|
(js--re-search-backward "\\_<do\\_>" (point-at-bol) t)
|
|
|
|
|
(or (looking-at "\\_<do\\_>")
|
|
|
|
|
(let ((saved-indent (current-indentation)))
|
|
|
|
|
(while (and (js--re-search-backward "^\\s-*\\_<" nil t)
|
|
|
|
|
(/= (current-indentation) saved-indent)))
|
|
|
|
|
(and (looking-at "\\s-*\\_<do\\_>")
|
|
|
|
|
(not (js--re-search-forward
|
|
|
|
|
"\\_<while\\_>" (point-at-eol) t))
|
|
|
|
|
(= (current-indentation) saved-indent)))))))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defun js--ctrl-statement-indentation ()
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Helper function for `js--proper-indentation'.
|
|
|
|
|
Return the proper indentation of the current line if it starts
|
|
|
|
|
the body of a control statement without braces; otherwise, return
|
|
|
|
|
nil."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(save-excursion
|
|
|
|
|
(back-to-indentation)
|
|
|
|
|
(when (save-excursion
|
|
|
|
|
(and (not (eq (point-at-bol) (point-min)))
|
|
|
|
|
(not (looking-at "[{]"))
|
2013-11-25 00:01:08 +02:00
|
|
|
|
(js--re-search-backward "[[:graph:]]" nil t)
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(progn
|
|
|
|
|
(or (eobp) (forward-char))
|
|
|
|
|
(when (= (char-before) ?\)) (backward-list))
|
|
|
|
|
(skip-syntax-backward " ")
|
|
|
|
|
(skip-syntax-backward "w_")
|
|
|
|
|
(looking-at js--possibly-braceless-keyword-re))
|
2015-12-01 05:40:57 +02:00
|
|
|
|
(memq (char-before) '(?\s ?\t ?\n ?\}))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(not (js--end-of-do-while-loop-p))))
|
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char (match-beginning 0))
|
|
|
|
|
(+ (current-indentation) js-indent-level)))))
|
|
|
|
|
|
|
|
|
|
(defun js--get-c-offset (symbol anchor)
|
|
|
|
|
(let ((c-offsets-alist
|
|
|
|
|
(list (cons 'c js-comment-lineup-func))))
|
|
|
|
|
(c-get-syntactic-indentation (list (cons symbol anchor)))))
|
|
|
|
|
|
2013-12-08 18:08:45 +02:00
|
|
|
|
(defun js--same-line (pos)
|
|
|
|
|
(and (>= pos (point-at-bol))
|
|
|
|
|
(<= pos (point-at-eol))))
|
|
|
|
|
|
2013-01-11 18:24:52 -05:00
|
|
|
|
(defun js--multi-line-declaration-indentation ()
|
|
|
|
|
"Helper function for `js--proper-indentation'.
|
|
|
|
|
Return the proper indentation of the current line if it belongs to a declaration
|
|
|
|
|
statement spanning multiple lines; otherwise, return nil."
|
2016-12-17 01:52:12 +02:00
|
|
|
|
(let (forward-sexp-function ; Use Lisp version.
|
|
|
|
|
at-opening-bracket)
|
2013-01-11 18:24:52 -05:00
|
|
|
|
(save-excursion
|
|
|
|
|
(back-to-indentation)
|
|
|
|
|
(when (not (looking-at js--declaration-keyword-re))
|
2017-10-26 02:43:33 +03:00
|
|
|
|
(let ((pt (point)))
|
|
|
|
|
(when (looking-at js--indent-operator-re)
|
|
|
|
|
(goto-char (match-end 0)))
|
|
|
|
|
;; The "operator" is probably a regexp literal opener.
|
|
|
|
|
(when (nth 3 (syntax-ppss))
|
|
|
|
|
(goto-char pt)))
|
2013-01-11 18:24:52 -05:00
|
|
|
|
(while (and (not at-opening-bracket)
|
|
|
|
|
(not (bobp))
|
|
|
|
|
(let ((pos (point)))
|
|
|
|
|
(save-excursion
|
|
|
|
|
(js--backward-syntactic-ws)
|
|
|
|
|
(or (eq (char-before) ?,)
|
|
|
|
|
(and (not (eq (char-before) ?\;))
|
|
|
|
|
(prog2
|
2013-03-07 20:08:33 +04:00
|
|
|
|
(skip-syntax-backward ".")
|
2013-01-11 18:24:52 -05:00
|
|
|
|
(looking-at js--indent-operator-re)
|
|
|
|
|
(js--backward-syntactic-ws))
|
|
|
|
|
(not (eq (char-before) ?\;)))
|
2013-12-08 18:08:45 +02:00
|
|
|
|
(js--same-line pos)))))
|
2013-02-13 01:53:07 +01:00
|
|
|
|
(condition-case nil
|
2013-01-11 18:24:52 -05:00
|
|
|
|
(backward-sexp)
|
|
|
|
|
(scan-error (setq at-opening-bracket t))))
|
|
|
|
|
(when (looking-at js--declaration-keyword-re)
|
|
|
|
|
(goto-char (match-end 0))
|
|
|
|
|
(1+ (current-column)))))))
|
|
|
|
|
|
2013-12-08 18:08:45 +02:00
|
|
|
|
(defun js--indent-in-array-comp (bracket)
|
|
|
|
|
"Return non-nil if we think we're in an array comprehension.
|
|
|
|
|
In particular, return the buffer position of the first `for' kwd."
|
|
|
|
|
(let ((end (point)))
|
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char bracket)
|
|
|
|
|
(when (looking-at "\\[")
|
|
|
|
|
(forward-char 1)
|
|
|
|
|
(js--forward-syntactic-ws)
|
|
|
|
|
(if (looking-at "[[{]")
|
|
|
|
|
(let (forward-sexp-function) ; Use Lisp version.
|
2017-02-24 00:24:17 -07:00
|
|
|
|
(condition-case nil
|
|
|
|
|
(progn
|
|
|
|
|
(forward-sexp) ; Skip destructuring form.
|
|
|
|
|
(js--forward-syntactic-ws)
|
|
|
|
|
(if (and (/= (char-after) ?,) ; Regular array.
|
|
|
|
|
(looking-at "for"))
|
|
|
|
|
(match-beginning 0)))
|
|
|
|
|
(scan-error
|
|
|
|
|
;; Nothing to do here.
|
|
|
|
|
nil)))
|
2013-12-08 18:08:45 +02:00
|
|
|
|
;; To skip arbitrary expressions we need the parser,
|
|
|
|
|
;; so we'll just guess at it.
|
|
|
|
|
(if (and (> end (point)) ; Not empty literal.
|
2016-04-28 02:00:23 +03:00
|
|
|
|
(re-search-forward "[^,]]* \\(for\\_>\\)" end t)
|
2013-12-08 18:08:45 +02:00
|
|
|
|
;; Not inside comment or string literal.
|
2016-04-28 02:00:23 +03:00
|
|
|
|
(let ((status (parse-partial-sexp bracket (point))))
|
|
|
|
|
(and (= 1 (car status))
|
|
|
|
|
(not (nth 8 status)))))
|
2013-12-08 18:08:45 +02:00
|
|
|
|
(match-beginning 1)))))))
|
|
|
|
|
|
|
|
|
|
(defun js--array-comp-indentation (bracket for-kwd)
|
|
|
|
|
(if (js--same-line for-kwd)
|
|
|
|
|
;; First continuation line.
|
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char bracket)
|
|
|
|
|
(forward-char 1)
|
|
|
|
|
(skip-chars-forward " \t")
|
|
|
|
|
(current-column))
|
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char for-kwd)
|
|
|
|
|
(current-column))))
|
|
|
|
|
|
2015-03-07 18:01:05 -08:00
|
|
|
|
(defun js--maybe-goto-declaration-keyword-end (parse-status)
|
|
|
|
|
"Helper function for `js--proper-indentation'.
|
2015-03-10 16:29:01 -07:00
|
|
|
|
Depending on the value of `js-indent-first-init', move
|
2015-03-07 18:01:05 -08:00
|
|
|
|
point to the end of a variable declaration keyword so that
|
|
|
|
|
indentation is aligned to that column."
|
|
|
|
|
(cond
|
2015-03-10 16:29:01 -07:00
|
|
|
|
((eq js-indent-first-init t)
|
2015-03-07 18:01:05 -08:00
|
|
|
|
(when (looking-at js--declaration-keyword-re)
|
|
|
|
|
(goto-char (1+ (match-end 0)))))
|
2015-03-10 16:29:01 -07:00
|
|
|
|
((eq js-indent-first-init 'dynamic)
|
2015-03-07 18:01:05 -08:00
|
|
|
|
(let ((bracket (nth 1 parse-status))
|
|
|
|
|
declaration-keyword-end
|
|
|
|
|
at-closing-bracket-p
|
2016-12-17 01:52:12 +02:00
|
|
|
|
forward-sexp-function ; Use Lisp version.
|
2015-03-07 18:01:05 -08:00
|
|
|
|
comma-p)
|
|
|
|
|
(when (looking-at js--declaration-keyword-re)
|
|
|
|
|
(setq declaration-keyword-end (match-end 0))
|
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char bracket)
|
|
|
|
|
(setq at-closing-bracket-p
|
|
|
|
|
(condition-case nil
|
|
|
|
|
(progn
|
|
|
|
|
(forward-sexp)
|
|
|
|
|
t)
|
|
|
|
|
(error nil)))
|
|
|
|
|
(when at-closing-bracket-p
|
|
|
|
|
(while (forward-comment 1))
|
|
|
|
|
(setq comma-p (looking-at-p ","))))
|
|
|
|
|
(when comma-p
|
|
|
|
|
(goto-char (1+ declaration-keyword-end))))))))
|
|
|
|
|
|
2019-02-09 12:26:21 -08:00
|
|
|
|
(defconst js--line-terminating-arrow-re "\\s-*=>\\s-*\\(/[/*]\\|$\\)"
|
|
|
|
|
"Regexp matching the last \"=>\" (arrow) token on a line.
|
|
|
|
|
Whitespace and comments around the arrow are ignored.")
|
|
|
|
|
|
|
|
|
|
(defun js--looking-at-broken-arrow-function-p ()
|
|
|
|
|
"Helper function for `js--proper-indentation'.
|
|
|
|
|
Return t if point is at the start of a (possibly async) arrow
|
|
|
|
|
function and the last non-comment, non-whitespace token of the
|
|
|
|
|
current line is the \"=>\" token."
|
|
|
|
|
(when (looking-at "\\s-*async\\s-*")
|
|
|
|
|
(goto-char (match-end 0)))
|
|
|
|
|
(cond
|
|
|
|
|
((eq (char-after) ?\()
|
|
|
|
|
(forward-list)
|
|
|
|
|
(looking-at-p js--line-terminating-arrow-re))
|
|
|
|
|
(t (looking-at-p
|
|
|
|
|
(concat js--name-re js--line-terminating-arrow-re)))))
|
|
|
|
|
|
Indent JSX as parsed in a JS context
Fixes the following issues (and re-fixes indentation issues initially
fixed but later re-broken by previous commits in the process of adding
comprehensive JSX support):
- https://github.com/mooz/js2-mode/issues/389#issuecomment-390766873
- https://github.com/mooz/js2-mode/issues/482
- Bug#32158
- https://github.com/mooz/js2-mode/issues/462
Previously, we delegated to sgml-mode functions for JSX indentation.
However, there were some problems with this approach:
- sgml-mode does not anticipate tags inside attributes when indenting,
which compromises JSX indentation inside JSXExpressionContainers
inside JSXAttributes.
- In previous iterations to provide comprehensive JSX support, it
proved tedious to disambiguate “<” and “>” as JS inequality
operators and arrow functions from opening and closing angle
brackets as part of SGML tags. That code evolved into a more
complete JSX parsing implementation for syntax-propertize rules for
font-locking, discarding the superfluous “<”/“>” disambiguation in
anticipation of using the improved JSX analysis for indentation.
- Using sgml-mode functions, we controlled JSX indentation using SGML
variables. However, JSX is a different thing than SGML; referencing
SGML in JS was a leaky abstraction.
To resolve these issues, use the text properties added by the JSX
syntax-propertize code to determine the boundaries of various aspects
of JSX syntax, and reimplement the sgml-mode indentation code in
js-mode with better respect to JSX indentation conventions.
* lisp/progmodes/js.el (js-jsx-attribute-offset): New variable to
provide a way for users to still control JSX attribute offsets as they
could with sgml-attribute-offset before. The value of this feature is
dubious IMO, but it’s trivial to keep it, so let’s do it just in case.
(js-jsx--goto-outermost-enclosing-curly): New function.
(js-jsx--enclosing-tag-pos): Refactor to be unbounded by curlies, so
this function can be used to find JSXExpressionContainers within JSX.
Fix bug where an enclosing JSXElement couldn’t be found when point was
at the start of its JSXClosingElement. Return the JSXClosingElement’s
position as well, so the JSXClosingElement can be indentified when
indenting and be indented like the matching JSXOpeningElement.
(js-jsx--at-enclosing-tag-child-p): js-jsx--enclosing-tag-pos now
returns a list rather than a cons, so retrieve the JSXOpeningElement’s
end position from a list.
(js-jsx--context, js-jsx--indenting): New function and variable.
(js-jsx--indentation): New function replacing the prior
js-jsx--indent* functions and js-jsx-indent-line’s implementation.
Use the JSX parsing performed in a JS context to more accurately
calculate JSX indentation than by delegating to sgml-mode functions.
(js--proper-indentation): Use js-jsx--indentation as yet another type
of indentation.
(js-jsx--as-sgml, js-jsx--outermost-enclosing-tag-pos)
(js-jsx--indentation-type, js-jsx--indent-line-in-expression)
(js-jsx--indent-n+1th-line): Remove obsolete functions.
(js-jsx-indent-line): Refactor nearly-obsolete function to behave the
same as it usually would before these changes, without respect to the
binding of js-jsx-syntax.
(js-jsx-mode): Remove obsolete documentation about the use of SGML
variables to control indentation, and don’t bind indent-line-function
any more, because it is no longer necessary given the new
implementation of js-jsx-indent-line.
2019-03-23 14:22:35 -07:00
|
|
|
|
(defun js-jsx--context ()
|
|
|
|
|
"Determine JSX context and move to enclosing JSX."
|
|
|
|
|
(let ((pos (point))
|
|
|
|
|
(parse-status (syntax-ppss))
|
|
|
|
|
(enclosing-tag-pos (js-jsx--enclosing-tag-pos)))
|
|
|
|
|
(when enclosing-tag-pos
|
|
|
|
|
(if (< pos (nth 1 enclosing-tag-pos))
|
|
|
|
|
(if (nth 3 parse-status)
|
|
|
|
|
(list 'string (nth 8 parse-status))
|
|
|
|
|
(list 'tag (nth 0 enclosing-tag-pos) (nth 1 enclosing-tag-pos)))
|
|
|
|
|
(list 'text (nth 0 enclosing-tag-pos) (nth 2 enclosing-tag-pos))))))
|
|
|
|
|
|
|
|
|
|
(defvar js-jsx--indenting nil
|
|
|
|
|
"Flag to prevent infinite recursion while indenting JSX.")
|
|
|
|
|
|
|
|
|
|
(defun js-jsx--indentation (parse-status)
|
|
|
|
|
"Helper function for `js--proper-indentation'.
|
|
|
|
|
Return the proper indentation of the current line if it is part
|
|
|
|
|
of a JSXElement expression spanning multiple lines; otherwise,
|
|
|
|
|
return nil."
|
|
|
|
|
(let ((current-line (line-number-at-pos))
|
|
|
|
|
(curly-pos (js-jsx--enclosing-curly-pos))
|
|
|
|
|
nth-context context expr-p beg-line col
|
|
|
|
|
forward-sexp-function) ; Use the Lisp version.
|
|
|
|
|
;; Find the immediate context for indentation information, but
|
|
|
|
|
;; keep going to determine that point is at the N+1th line of
|
|
|
|
|
;; multiline JSX.
|
|
|
|
|
(save-excursion
|
|
|
|
|
(while
|
|
|
|
|
(and
|
|
|
|
|
(setq nth-context (js-jsx--context))
|
|
|
|
|
(progn
|
|
|
|
|
(unless context
|
|
|
|
|
(setq context nth-context)
|
|
|
|
|
(setq expr-p (and curly-pos (< (point) curly-pos))))
|
|
|
|
|
(setq beg-line (line-number-at-pos))
|
|
|
|
|
(and
|
|
|
|
|
(= beg-line current-line)
|
|
|
|
|
(or (not curly-pos) (> (point) curly-pos)))))))
|
|
|
|
|
(when (and context (> current-line beg-line))
|
|
|
|
|
(save-excursion
|
|
|
|
|
;; The column calculation is based on `sgml-calculate-indent'.
|
|
|
|
|
(setq col (pcase (nth 0 context)
|
|
|
|
|
|
|
|
|
|
('string
|
|
|
|
|
;; Go back to previous non-empty line.
|
|
|
|
|
(while (and (> (point) (nth 1 context))
|
|
|
|
|
(zerop (forward-line -1))
|
|
|
|
|
(looking-at "[ \t]*$")))
|
|
|
|
|
(if (> (point) (nth 1 context))
|
|
|
|
|
;; Previous line is inside the string.
|
|
|
|
|
(current-indentation)
|
|
|
|
|
(goto-char (nth 1 context))
|
|
|
|
|
(1+ (current-column))))
|
|
|
|
|
|
|
|
|
|
('tag
|
|
|
|
|
;; Special JSX indentation rule: a “dangling”
|
|
|
|
|
;; closing angle bracket on its own line is
|
|
|
|
|
;; indented at the same level as the opening
|
|
|
|
|
;; angle bracket of the JSXElement. Otherwise,
|
|
|
|
|
;; indent JSXAttribute space like SGML.
|
|
|
|
|
(if (progn
|
|
|
|
|
(goto-char (nth 2 context))
|
|
|
|
|
(and (= current-line (line-number-at-pos))
|
|
|
|
|
(looking-back "^\\s-*/?>" (line-beginning-position))))
|
|
|
|
|
(progn
|
|
|
|
|
(goto-char (nth 1 context))
|
|
|
|
|
(current-column))
|
|
|
|
|
;; Indent JSXAttribute space like SGML.
|
|
|
|
|
(goto-char (nth 1 context))
|
|
|
|
|
;; Skip tag name:
|
|
|
|
|
(skip-chars-forward " \t")
|
|
|
|
|
(skip-chars-forward "^ \t\n")
|
|
|
|
|
(skip-chars-forward " \t")
|
|
|
|
|
(if (not (eolp))
|
|
|
|
|
(current-column)
|
|
|
|
|
;; This is the first attribute: indent.
|
|
|
|
|
(goto-char (+ (nth 1 context) js-jsx-attribute-offset))
|
|
|
|
|
(+ (current-column) js-indent-level))))
|
|
|
|
|
|
|
|
|
|
('text
|
|
|
|
|
;; Indent to reflect nesting.
|
|
|
|
|
(goto-char (nth 1 context))
|
|
|
|
|
(+ (current-column)
|
|
|
|
|
;; The last line isn’t nested, but the rest are.
|
|
|
|
|
(if (or (not (nth 2 context)) ; Unclosed.
|
|
|
|
|
(< current-line (line-number-at-pos (nth 2 context))))
|
|
|
|
|
js-indent-level
|
|
|
|
|
0)))
|
|
|
|
|
|
|
|
|
|
)))
|
|
|
|
|
;; When indenting a JSXExpressionContainer expression, use JSX
|
|
|
|
|
;; indentation as a minimum, and use regular JS indentation if
|
|
|
|
|
;; it’s deeper.
|
|
|
|
|
(if expr-p
|
|
|
|
|
(max (+ col
|
|
|
|
|
;; An expression in a JSXExpressionContainer in a
|
|
|
|
|
;; JSXAttribute should be indented more, except on
|
|
|
|
|
;; the ending line of the JSXExpressionContainer.
|
|
|
|
|
(if (and (eq (nth 0 context) 'tag)
|
|
|
|
|
(< current-line
|
|
|
|
|
(save-excursion
|
|
|
|
|
(js-jsx--goto-outermost-enclosing-curly
|
|
|
|
|
(nth 1 context))
|
|
|
|
|
(forward-sexp)
|
|
|
|
|
(line-number-at-pos))))
|
|
|
|
|
js-indent-level
|
|
|
|
|
0))
|
|
|
|
|
(let ((js-jsx--indenting t)) ; Prevent recursion.
|
|
|
|
|
(js--proper-indentation parse-status)))
|
|
|
|
|
col))))
|
|
|
|
|
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(defun js--proper-indentation (parse-status)
|
|
|
|
|
"Return the proper indentation for the current line."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(back-to-indentation)
|
2013-12-08 18:08:45 +02:00
|
|
|
|
(cond ((nth 4 parse-status) ; inside comment
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(js--get-c-offset 'c (nth 8 parse-status)))
|
2013-12-08 18:08:45 +02:00
|
|
|
|
((nth 3 parse-status) 0) ; inside string
|
Indent JSX as parsed in a JS context
Fixes the following issues (and re-fixes indentation issues initially
fixed but later re-broken by previous commits in the process of adding
comprehensive JSX support):
- https://github.com/mooz/js2-mode/issues/389#issuecomment-390766873
- https://github.com/mooz/js2-mode/issues/482
- Bug#32158
- https://github.com/mooz/js2-mode/issues/462
Previously, we delegated to sgml-mode functions for JSX indentation.
However, there were some problems with this approach:
- sgml-mode does not anticipate tags inside attributes when indenting,
which compromises JSX indentation inside JSXExpressionContainers
inside JSXAttributes.
- In previous iterations to provide comprehensive JSX support, it
proved tedious to disambiguate “<” and “>” as JS inequality
operators and arrow functions from opening and closing angle
brackets as part of SGML tags. That code evolved into a more
complete JSX parsing implementation for syntax-propertize rules for
font-locking, discarding the superfluous “<”/“>” disambiguation in
anticipation of using the improved JSX analysis for indentation.
- Using sgml-mode functions, we controlled JSX indentation using SGML
variables. However, JSX is a different thing than SGML; referencing
SGML in JS was a leaky abstraction.
To resolve these issues, use the text properties added by the JSX
syntax-propertize code to determine the boundaries of various aspects
of JSX syntax, and reimplement the sgml-mode indentation code in
js-mode with better respect to JSX indentation conventions.
* lisp/progmodes/js.el (js-jsx-attribute-offset): New variable to
provide a way for users to still control JSX attribute offsets as they
could with sgml-attribute-offset before. The value of this feature is
dubious IMO, but it’s trivial to keep it, so let’s do it just in case.
(js-jsx--goto-outermost-enclosing-curly): New function.
(js-jsx--enclosing-tag-pos): Refactor to be unbounded by curlies, so
this function can be used to find JSXExpressionContainers within JSX.
Fix bug where an enclosing JSXElement couldn’t be found when point was
at the start of its JSXClosingElement. Return the JSXClosingElement’s
position as well, so the JSXClosingElement can be indentified when
indenting and be indented like the matching JSXOpeningElement.
(js-jsx--at-enclosing-tag-child-p): js-jsx--enclosing-tag-pos now
returns a list rather than a cons, so retrieve the JSXOpeningElement’s
end position from a list.
(js-jsx--context, js-jsx--indenting): New function and variable.
(js-jsx--indentation): New function replacing the prior
js-jsx--indent* functions and js-jsx-indent-line’s implementation.
Use the JSX parsing performed in a JS context to more accurately
calculate JSX indentation than by delegating to sgml-mode functions.
(js--proper-indentation): Use js-jsx--indentation as yet another type
of indentation.
(js-jsx--as-sgml, js-jsx--outermost-enclosing-tag-pos)
(js-jsx--indentation-type, js-jsx--indent-line-in-expression)
(js-jsx--indent-n+1th-line): Remove obsolete functions.
(js-jsx-indent-line): Refactor nearly-obsolete function to behave the
same as it usually would before these changes, without respect to the
binding of js-jsx-syntax.
(js-jsx-mode): Remove obsolete documentation about the use of SGML
variables to control indentation, and don’t bind indent-line-function
any more, because it is no longer necessary given the new
implementation of js-jsx-indent-line.
2019-03-23 14:22:35 -07:00
|
|
|
|
((when (and js-jsx-syntax (not js-jsx--indenting))
|
|
|
|
|
(save-excursion (js-jsx--indentation parse-status))))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
((eq (char-after) ?#) 0)
|
|
|
|
|
((save-excursion (js--beginning-of-macro)) 4)
|
2013-12-08 18:08:45 +02:00
|
|
|
|
;; Indent array comprehension continuation lines specially.
|
|
|
|
|
((let ((bracket (nth 1 parse-status))
|
|
|
|
|
beg)
|
|
|
|
|
(and bracket
|
|
|
|
|
(not (js--same-line bracket))
|
|
|
|
|
(setq beg (js--indent-in-array-comp bracket))
|
|
|
|
|
;; At or after the first loop?
|
|
|
|
|
(>= (point) beg)
|
|
|
|
|
(js--array-comp-indentation bracket beg))))
|
2017-01-12 23:15:00 -07:00
|
|
|
|
((js--chained-expression-p))
|
2013-12-08 18:08:45 +02:00
|
|
|
|
((js--ctrl-statement-indentation))
|
|
|
|
|
((js--multi-line-declaration-indentation))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
((nth 1 parse-status)
|
2010-08-26 16:09:31 -04:00
|
|
|
|
;; A single closing paren/bracket should be indented at the
|
|
|
|
|
;; same level as the opening statement. Same goes for
|
|
|
|
|
;; "case" and "default".
|
2013-12-08 18:08:45 +02:00
|
|
|
|
(let ((same-indent-p (looking-at "[]})]"))
|
|
|
|
|
(switch-keyword-p (looking-at "default\\_>\\|case\\_>[^:]"))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(continued-expr-p (js--continued-expression-p)))
|
2010-08-26 16:09:31 -04:00
|
|
|
|
(goto-char (nth 1 parse-status)) ; go to the opening char
|
2017-07-01 13:09:20 +02:00
|
|
|
|
(if (or (not js-indent-align-list-continuation)
|
2019-02-09 12:26:21 -08:00
|
|
|
|
(looking-at "[({[]\\s-*\\(/[/*]\\|$\\)")
|
|
|
|
|
(save-excursion (forward-char) (js--looking-at-broken-arrow-function-p)))
|
2010-08-26 16:09:31 -04:00
|
|
|
|
(progn ; nothing following the opening paren/bracket
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(skip-syntax-backward " ")
|
2010-08-26 16:09:31 -04:00
|
|
|
|
(when (eq (char-before) ?\)) (backward-list))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(back-to-indentation)
|
2015-03-07 18:01:05 -08:00
|
|
|
|
(js--maybe-goto-declaration-keyword-end parse-status)
|
2013-12-08 18:08:45 +02:00
|
|
|
|
(let* ((in-switch-p (unless same-indent-p
|
|
|
|
|
(looking-at "\\_<switch\\_>")))
|
|
|
|
|
(same-indent-p (or same-indent-p
|
|
|
|
|
(and switch-keyword-p
|
|
|
|
|
in-switch-p)))
|
|
|
|
|
(indent
|
|
|
|
|
(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
|
|
|
|
|
(pcase (char-after (nth 1 parse-status))
|
|
|
|
|
(?\( js-paren-indent-offset)
|
|
|
|
|
(?\[ js-square-indent-offset)
|
|
|
|
|
(?\{ js-curly-indent-offset)))))))
|
|
|
|
|
(if in-switch-p
|
|
|
|
|
(+ indent js-switch-indent-offset)
|
|
|
|
|
indent)))
|
2010-08-26 16:09:31 -04:00
|
|
|
|
;; If there is something following the opening
|
|
|
|
|
;; paren/bracket, everything else should be indented at
|
|
|
|
|
;; the same level.
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(unless same-indent-p
|
|
|
|
|
(forward-char)
|
|
|
|
|
(skip-chars-forward " \t"))
|
|
|
|
|
(current-column))))
|
|
|
|
|
|
|
|
|
|
((js--continued-expression-p)
|
|
|
|
|
(+ js-indent-level js-expr-indent-offset))
|
2017-03-23 11:33:22 -06:00
|
|
|
|
(t (prog-first-column)))))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defun js-indent-line ()
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Indent the current line as JavaScript."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(interactive)
|
2014-02-12 08:23:42 +02:00
|
|
|
|
(let* ((parse-status
|
|
|
|
|
(save-excursion (syntax-ppss (point-at-bol))))
|
2014-05-31 21:53:04 -04:00
|
|
|
|
(offset (- (point) (save-excursion (back-to-indentation) (point)))))
|
2015-04-03 06:37:12 +03:00
|
|
|
|
(unless (nth 3 parse-status)
|
2015-04-03 07:13:14 +03:00
|
|
|
|
(indent-line-to (js--proper-indentation parse-status))
|
|
|
|
|
(when (> offset 0) (forward-char offset)))))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
2015-10-30 23:55:24 -07:00
|
|
|
|
(defun js-jsx-indent-line ()
|
Indent JSX as parsed in a JS context
Fixes the following issues (and re-fixes indentation issues initially
fixed but later re-broken by previous commits in the process of adding
comprehensive JSX support):
- https://github.com/mooz/js2-mode/issues/389#issuecomment-390766873
- https://github.com/mooz/js2-mode/issues/482
- Bug#32158
- https://github.com/mooz/js2-mode/issues/462
Previously, we delegated to sgml-mode functions for JSX indentation.
However, there were some problems with this approach:
- sgml-mode does not anticipate tags inside attributes when indenting,
which compromises JSX indentation inside JSXExpressionContainers
inside JSXAttributes.
- In previous iterations to provide comprehensive JSX support, it
proved tedious to disambiguate “<” and “>” as JS inequality
operators and arrow functions from opening and closing angle
brackets as part of SGML tags. That code evolved into a more
complete JSX parsing implementation for syntax-propertize rules for
font-locking, discarding the superfluous “<”/“>” disambiguation in
anticipation of using the improved JSX analysis for indentation.
- Using sgml-mode functions, we controlled JSX indentation using SGML
variables. However, JSX is a different thing than SGML; referencing
SGML in JS was a leaky abstraction.
To resolve these issues, use the text properties added by the JSX
syntax-propertize code to determine the boundaries of various aspects
of JSX syntax, and reimplement the sgml-mode indentation code in
js-mode with better respect to JSX indentation conventions.
* lisp/progmodes/js.el (js-jsx-attribute-offset): New variable to
provide a way for users to still control JSX attribute offsets as they
could with sgml-attribute-offset before. The value of this feature is
dubious IMO, but it’s trivial to keep it, so let’s do it just in case.
(js-jsx--goto-outermost-enclosing-curly): New function.
(js-jsx--enclosing-tag-pos): Refactor to be unbounded by curlies, so
this function can be used to find JSXExpressionContainers within JSX.
Fix bug where an enclosing JSXElement couldn’t be found when point was
at the start of its JSXClosingElement. Return the JSXClosingElement’s
position as well, so the JSXClosingElement can be indentified when
indenting and be indented like the matching JSXOpeningElement.
(js-jsx--at-enclosing-tag-child-p): js-jsx--enclosing-tag-pos now
returns a list rather than a cons, so retrieve the JSXOpeningElement’s
end position from a list.
(js-jsx--context, js-jsx--indenting): New function and variable.
(js-jsx--indentation): New function replacing the prior
js-jsx--indent* functions and js-jsx-indent-line’s implementation.
Use the JSX parsing performed in a JS context to more accurately
calculate JSX indentation than by delegating to sgml-mode functions.
(js--proper-indentation): Use js-jsx--indentation as yet another type
of indentation.
(js-jsx--as-sgml, js-jsx--outermost-enclosing-tag-pos)
(js-jsx--indentation-type, js-jsx--indent-line-in-expression)
(js-jsx--indent-n+1th-line): Remove obsolete functions.
(js-jsx-indent-line): Refactor nearly-obsolete function to behave the
same as it usually would before these changes, without respect to the
binding of js-jsx-syntax.
(js-jsx-mode): Remove obsolete documentation about the use of SGML
variables to control indentation, and don’t bind indent-line-function
any more, because it is no longer necessary given the new
implementation of js-jsx-indent-line.
2019-03-23 14:22:35 -07:00
|
|
|
|
"Indent the current line as JavaScript+JSX."
|
2015-10-30 23:55:24 -07:00
|
|
|
|
(interactive)
|
Indent JSX as parsed in a JS context
Fixes the following issues (and re-fixes indentation issues initially
fixed but later re-broken by previous commits in the process of adding
comprehensive JSX support):
- https://github.com/mooz/js2-mode/issues/389#issuecomment-390766873
- https://github.com/mooz/js2-mode/issues/482
- Bug#32158
- https://github.com/mooz/js2-mode/issues/462
Previously, we delegated to sgml-mode functions for JSX indentation.
However, there were some problems with this approach:
- sgml-mode does not anticipate tags inside attributes when indenting,
which compromises JSX indentation inside JSXExpressionContainers
inside JSXAttributes.
- In previous iterations to provide comprehensive JSX support, it
proved tedious to disambiguate “<” and “>” as JS inequality
operators and arrow functions from opening and closing angle
brackets as part of SGML tags. That code evolved into a more
complete JSX parsing implementation for syntax-propertize rules for
font-locking, discarding the superfluous “<”/“>” disambiguation in
anticipation of using the improved JSX analysis for indentation.
- Using sgml-mode functions, we controlled JSX indentation using SGML
variables. However, JSX is a different thing than SGML; referencing
SGML in JS was a leaky abstraction.
To resolve these issues, use the text properties added by the JSX
syntax-propertize code to determine the boundaries of various aspects
of JSX syntax, and reimplement the sgml-mode indentation code in
js-mode with better respect to JSX indentation conventions.
* lisp/progmodes/js.el (js-jsx-attribute-offset): New variable to
provide a way for users to still control JSX attribute offsets as they
could with sgml-attribute-offset before. The value of this feature is
dubious IMO, but it’s trivial to keep it, so let’s do it just in case.
(js-jsx--goto-outermost-enclosing-curly): New function.
(js-jsx--enclosing-tag-pos): Refactor to be unbounded by curlies, so
this function can be used to find JSXExpressionContainers within JSX.
Fix bug where an enclosing JSXElement couldn’t be found when point was
at the start of its JSXClosingElement. Return the JSXClosingElement’s
position as well, so the JSXClosingElement can be indentified when
indenting and be indented like the matching JSXOpeningElement.
(js-jsx--at-enclosing-tag-child-p): js-jsx--enclosing-tag-pos now
returns a list rather than a cons, so retrieve the JSXOpeningElement’s
end position from a list.
(js-jsx--context, js-jsx--indenting): New function and variable.
(js-jsx--indentation): New function replacing the prior
js-jsx--indent* functions and js-jsx-indent-line’s implementation.
Use the JSX parsing performed in a JS context to more accurately
calculate JSX indentation than by delegating to sgml-mode functions.
(js--proper-indentation): Use js-jsx--indentation as yet another type
of indentation.
(js-jsx--as-sgml, js-jsx--outermost-enclosing-tag-pos)
(js-jsx--indentation-type, js-jsx--indent-line-in-expression)
(js-jsx--indent-n+1th-line): Remove obsolete functions.
(js-jsx-indent-line): Refactor nearly-obsolete function to behave the
same as it usually would before these changes, without respect to the
binding of js-jsx-syntax.
(js-jsx-mode): Remove obsolete documentation about the use of SGML
variables to control indentation, and don’t bind indent-line-function
any more, because it is no longer necessary given the new
implementation of js-jsx-indent-line.
2019-03-23 14:22:35 -07:00
|
|
|
|
(let ((js-jsx-syntax t)) (js-indent-line)))
|
2015-10-30 23:55:24 -07:00
|
|
|
|
|
2009-08-14 23:02:38 +00:00
|
|
|
|
;;; Filling
|
|
|
|
|
|
2012-11-08 14:44:52 -05:00
|
|
|
|
(defvar js--filling-paragraph nil)
|
|
|
|
|
|
|
|
|
|
;; FIXME: Such redefinitions are bad style. We should try and use some other
|
|
|
|
|
;; way to get the same result.
|
2018-09-14 10:23:39 -04:00
|
|
|
|
(defun js--fill-c-advice (js-fun)
|
|
|
|
|
(lambda (orig-fun &rest args)
|
|
|
|
|
(if js--filling-paragraph
|
|
|
|
|
(funcall js-fun (car args))
|
|
|
|
|
(apply orig-fun args))))
|
|
|
|
|
|
|
|
|
|
(advice-add 'c-forward-sws
|
|
|
|
|
:around (js--fill-c-advice #'js--forward-syntactic-ws))
|
|
|
|
|
(advice-add 'c-backward-sws
|
|
|
|
|
:around (js--fill-c-advice #'js--backward-syntactic-ws))
|
|
|
|
|
(advice-add 'c-beginning-of-macro
|
|
|
|
|
:around (js--fill-c-advice #'js--beginning-of-macro))
|
|
|
|
|
|
|
|
|
|
(define-obsolete-function-alias 'js-c-fill-paragraph #'js-fill-paragraph "27.1")
|
|
|
|
|
(defun js-fill-paragraph (&optional justify)
|
|
|
|
|
"Fill the paragraph for Javascript code."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(interactive "*P")
|
2012-11-08 14:44:52 -05:00
|
|
|
|
(let ((js--filling-paragraph t)
|
2016-05-04 08:53:00 -04:00
|
|
|
|
(fill-paragraph-function #'c-fill-paragraph))
|
2012-11-08 14:44:52 -05:00
|
|
|
|
(c-fill-paragraph justify)))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
2017-08-27 12:54:01 -06:00
|
|
|
|
(defun js-do-auto-fill ()
|
|
|
|
|
(let ((js--filling-paragraph t))
|
|
|
|
|
(c-do-auto-fill)))
|
|
|
|
|
|
2009-08-14 23:02:38 +00:00
|
|
|
|
;;; Type database and Imenu
|
|
|
|
|
|
|
|
|
|
;; We maintain a cache of semantic information, i.e., the classes and
|
|
|
|
|
;; functions we've encountered so far. In order to avoid having to
|
|
|
|
|
;; re-parse the buffer on every change, we cache the parse state at
|
|
|
|
|
;; each interesting point in the buffer. Each parse state is a
|
|
|
|
|
;; modified copy of the previous one, or in the case of the first
|
|
|
|
|
;; parse state, the empty state.
|
|
|
|
|
;;
|
|
|
|
|
;; The parse state itself is just a stack of js--pitem
|
|
|
|
|
;; instances. It starts off containing one element that is never
|
|
|
|
|
;; closed, that is initially js--initial-pitem.
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defun js--pitem-format (pitem)
|
|
|
|
|
(let ((name (js--pitem-name pitem))
|
|
|
|
|
(type (js--pitem-type pitem)))
|
|
|
|
|
|
|
|
|
|
(format "name:%S type:%S"
|
|
|
|
|
name
|
|
|
|
|
(if (atom type)
|
|
|
|
|
type
|
|
|
|
|
(plist-get type :name)))))
|
|
|
|
|
|
|
|
|
|
(defun js--make-merged-item (item child name-parts)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Helper function for `js--splice-into-items'.
|
|
|
|
|
Return a new item that is the result of merging CHILD into
|
* international/ucs-normalize.el (ucs-normalize-sort, quick-check-list):
Fix typos in docstrings.
* progmodes/js.el (js--macro-decl-re): Doc fix.
(js--plain-method-re, js--split-name): Refloc docstring.
(js--class-styles, js--make-merged-item, js--splice-into-items):
Fix typos in docstrings; reflow docstrings.
(js--maybe-join, js--function-prologue-beginning, js--flush-caches)
(js--variable-decl-matcher, js--inside-pitem-p)
(js--parse-state-at-point, js--get-all-known-symbols)
(js--symbol-history, js-find-symbol, js--js-references)
(js--moz-interactor, js--js-encode-value, js--read-tab):
Fix typos in docstrings.
2009-08-28 18:22:30 +00:00
|
|
|
|
ITEM. NAME-PARTS is a list of parts of the name of CHILD
|
|
|
|
|
that we haven't consumed yet."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(js--debug "js--make-merged-item: {%s} into {%s}"
|
|
|
|
|
(js--pitem-format child)
|
|
|
|
|
(js--pitem-format item))
|
|
|
|
|
|
|
|
|
|
;; If the item we're merging into isn't a class, make it into one
|
|
|
|
|
(unless (consp (js--pitem-type item))
|
|
|
|
|
(js--debug "js--make-merged-item: changing dest into class")
|
|
|
|
|
(setq item (make-js--pitem
|
|
|
|
|
:children (list item)
|
|
|
|
|
|
|
|
|
|
;; Use the child's class-style if it's available
|
|
|
|
|
:type (if (atom (js--pitem-type child))
|
|
|
|
|
js--dummy-class-style
|
|
|
|
|
(js--pitem-type child))
|
|
|
|
|
|
|
|
|
|
:name (js--pitem-strname item))))
|
|
|
|
|
|
|
|
|
|
;; Now we can merge either a function or a class into a class
|
|
|
|
|
(cons (cond
|
|
|
|
|
((cdr name-parts)
|
|
|
|
|
(js--debug "js--make-merged-item: recursing")
|
|
|
|
|
;; if we have more name-parts to go before we get to the
|
|
|
|
|
;; bottom of the class hierarchy, call the merger
|
|
|
|
|
;; recursively
|
|
|
|
|
(js--splice-into-items (car item) child
|
|
|
|
|
(cdr name-parts)))
|
|
|
|
|
|
|
|
|
|
((atom (js--pitem-type child))
|
|
|
|
|
(js--debug "js--make-merged-item: straight merge")
|
|
|
|
|
;; Not merging a class, but something else, so just prepend
|
|
|
|
|
;; it
|
|
|
|
|
(cons child (car item)))
|
|
|
|
|
|
|
|
|
|
(t
|
|
|
|
|
;; Otherwise, merge the new child's items into those
|
|
|
|
|
;; of the new class
|
|
|
|
|
(js--debug "js--make-merged-item: merging class contents")
|
|
|
|
|
(append (car child) (car item))))
|
|
|
|
|
(cdr item)))
|
|
|
|
|
|
|
|
|
|
(defun js--pitem-strname (pitem)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Last part of the name of PITEM, as a string or symbol."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(let ((name (js--pitem-name pitem)))
|
|
|
|
|
(if (consp name)
|
|
|
|
|
(car (last name))
|
|
|
|
|
name)))
|
|
|
|
|
|
|
|
|
|
(defun js--splice-into-items (items child name-parts)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Splice CHILD into the `js--pitem' ITEMS at NAME-PARTS.
|
* international/ucs-normalize.el (ucs-normalize-sort, quick-check-list):
Fix typos in docstrings.
* progmodes/js.el (js--macro-decl-re): Doc fix.
(js--plain-method-re, js--split-name): Refloc docstring.
(js--class-styles, js--make-merged-item, js--splice-into-items):
Fix typos in docstrings; reflow docstrings.
(js--maybe-join, js--function-prologue-beginning, js--flush-caches)
(js--variable-decl-matcher, js--inside-pitem-p)
(js--parse-state-at-point, js--get-all-known-symbols)
(js--symbol-history, js-find-symbol, js--js-references)
(js--moz-interactor, js--js-encode-value, js--read-tab):
Fix typos in docstrings.
2009-08-28 18:22:30 +00:00
|
|
|
|
If a class doesn't exist in the tree, create it. Return
|
|
|
|
|
the new items list. NAME-PARTS is a list of strings given
|
|
|
|
|
the broken-down class name of the item to insert."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(let ((top-name (car name-parts))
|
|
|
|
|
(item-ptr items)
|
2011-04-22 20:44:26 +02:00
|
|
|
|
new-items last-new-item new-cons)
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(js--debug "js--splice-into-items: name-parts: %S items:%S"
|
|
|
|
|
name-parts
|
|
|
|
|
(mapcar #'js--pitem-name items))
|
|
|
|
|
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cl-assert (stringp top-name))
|
|
|
|
|
(cl-assert (> (length top-name) 0))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
;; If top-name isn't found in items, then we build a copy of items
|
|
|
|
|
;; and throw it away. But that's okay, since most of the time, we
|
|
|
|
|
;; *will* find an instance.
|
|
|
|
|
|
|
|
|
|
(while (and item-ptr
|
|
|
|
|
(cond ((equal (js--pitem-strname (car item-ptr)) top-name)
|
|
|
|
|
;; Okay, we found an entry with the right name. Splice
|
|
|
|
|
;; the merged item into the list...
|
|
|
|
|
(setq new-cons (cons (js--make-merged-item
|
|
|
|
|
(car item-ptr) child
|
|
|
|
|
name-parts)
|
|
|
|
|
(cdr item-ptr)))
|
|
|
|
|
|
|
|
|
|
(if last-new-item
|
|
|
|
|
(setcdr last-new-item new-cons)
|
|
|
|
|
(setq new-items new-cons))
|
|
|
|
|
|
|
|
|
|
;; ...and terminate the loop
|
|
|
|
|
nil)
|
|
|
|
|
|
|
|
|
|
(t
|
|
|
|
|
;; Otherwise, copy the current cons and move onto the
|
|
|
|
|
;; text. This is tricky; we keep track of the tail of
|
|
|
|
|
;; the list that begins with new-items in
|
|
|
|
|
;; last-new-item.
|
|
|
|
|
(setq new-cons (cons (car item-ptr) nil))
|
|
|
|
|
(if last-new-item
|
|
|
|
|
(setcdr last-new-item new-cons)
|
|
|
|
|
(setq new-items new-cons))
|
|
|
|
|
(setq last-new-item new-cons)
|
|
|
|
|
|
|
|
|
|
;; Go to the next cell in items
|
|
|
|
|
(setq item-ptr (cdr item-ptr))))))
|
|
|
|
|
|
|
|
|
|
(if item-ptr
|
|
|
|
|
;; Yay! We stopped because we found something, not because
|
|
|
|
|
;; we ran out of items to search. Just return the new
|
|
|
|
|
;; list.
|
|
|
|
|
(progn
|
|
|
|
|
(js--debug "search succeeded: %S" name-parts)
|
|
|
|
|
new-items)
|
|
|
|
|
|
|
|
|
|
;; We didn't find anything. If the child is a class and we don't
|
|
|
|
|
;; have any classes to drill down into, just push that class;
|
|
|
|
|
;; otherwise, make a fake class and carry on.
|
|
|
|
|
(js--debug "search failed: %S" name-parts)
|
|
|
|
|
(cons (if (cdr name-parts)
|
|
|
|
|
;; We have name-parts left to process. Make a fake
|
|
|
|
|
;; class for this particular part...
|
|
|
|
|
(make-js--pitem
|
|
|
|
|
;; ...and recursively digest the rest of the name
|
|
|
|
|
:children (js--splice-into-items
|
|
|
|
|
nil child (cdr name-parts))
|
|
|
|
|
:type js--dummy-class-style
|
|
|
|
|
:name top-name)
|
|
|
|
|
|
|
|
|
|
;; Otherwise, this is the only name we have, so stick
|
|
|
|
|
;; the item on the front of the list
|
|
|
|
|
child)
|
|
|
|
|
items))))
|
|
|
|
|
|
|
|
|
|
(defun js--pitem-add-child (pitem child)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Copy `js--pitem' PITEM, and push CHILD onto its list of children."
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cl-assert (integerp (js--pitem-h-begin child)))
|
|
|
|
|
(cl-assert (if (consp (js--pitem-name child))
|
|
|
|
|
(cl-loop for part in (js--pitem-name child)
|
|
|
|
|
always (stringp part))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
t))
|
|
|
|
|
|
|
|
|
|
;; This trick works because we know (based on our defstructs) that
|
|
|
|
|
;; the child list is always the first element, and so the second
|
|
|
|
|
;; element and beyond can be shared when we make our "copy".
|
|
|
|
|
(cons
|
|
|
|
|
|
|
|
|
|
(let ((name (js--pitem-name child))
|
|
|
|
|
(type (js--pitem-type child)))
|
|
|
|
|
|
|
|
|
|
(cond ((cdr-safe name) ; true if a list of at least two elements
|
|
|
|
|
;; Use slow path because we need class lookup
|
|
|
|
|
(js--splice-into-items (car pitem) child name))
|
|
|
|
|
|
|
|
|
|
((and (consp type)
|
|
|
|
|
(plist-get type :prototype))
|
|
|
|
|
|
|
|
|
|
;; Use slow path because we need class merging. We know
|
|
|
|
|
;; name is a list here because down in
|
|
|
|
|
;; `js--ensure-cache', we made sure to only add
|
|
|
|
|
;; class entries with lists for :name
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cl-assert (consp name))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(js--splice-into-items (car pitem) child name))
|
|
|
|
|
|
|
|
|
|
(t
|
|
|
|
|
;; Fast path
|
|
|
|
|
(cons child (car pitem)))))
|
|
|
|
|
|
|
|
|
|
(cdr pitem)))
|
|
|
|
|
|
|
|
|
|
(defun js--maybe-make-marker (location)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Return a marker for LOCATION if `imenu-use-markers' is non-nil."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(if imenu-use-markers
|
|
|
|
|
(set-marker (make-marker) location)
|
|
|
|
|
location))
|
|
|
|
|
|
|
|
|
|
(defun js--pitems-to-imenu (pitems unknown-ctr)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Convert PITEMS, a list of `js--pitem' structures, to imenu format."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(let (imenu-items pitem pitem-type pitem-name subitems)
|
|
|
|
|
|
|
|
|
|
(while (setq pitem (pop pitems))
|
|
|
|
|
(setq pitem-type (js--pitem-type pitem))
|
|
|
|
|
(setq pitem-name (js--pitem-strname pitem))
|
|
|
|
|
(when (eq pitem-name t)
|
|
|
|
|
(setq pitem-name (format "[unknown %s]"
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cl-incf (car unknown-ctr)))))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(cond
|
|
|
|
|
((memq pitem-type '(function macro))
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cl-assert (integerp (js--pitem-h-begin pitem)))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(push (cons pitem-name
|
|
|
|
|
(js--maybe-make-marker
|
|
|
|
|
(js--pitem-h-begin pitem)))
|
|
|
|
|
imenu-items))
|
|
|
|
|
|
|
|
|
|
((consp pitem-type) ; class definition
|
|
|
|
|
(setq subitems (js--pitems-to-imenu
|
|
|
|
|
(js--pitem-children pitem)
|
|
|
|
|
unknown-ctr))
|
|
|
|
|
(cond (subitems
|
|
|
|
|
(push (cons pitem-name subitems)
|
|
|
|
|
imenu-items))
|
|
|
|
|
|
|
|
|
|
((js--pitem-h-begin pitem)
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cl-assert (integerp (js--pitem-h-begin pitem)))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(setq subitems (list
|
|
|
|
|
(cons "[empty]"
|
|
|
|
|
(js--maybe-make-marker
|
|
|
|
|
(js--pitem-h-begin pitem)))))
|
|
|
|
|
(push (cons pitem-name subitems)
|
|
|
|
|
imenu-items))))
|
|
|
|
|
|
|
|
|
|
(t (error "Unknown item type: %S" pitem-type))))
|
|
|
|
|
|
|
|
|
|
imenu-items))
|
|
|
|
|
|
|
|
|
|
(defun js--imenu-create-index ()
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Return an imenu index for the current buffer."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(save-excursion
|
|
|
|
|
(save-restriction
|
|
|
|
|
(widen)
|
|
|
|
|
(goto-char (point-max))
|
|
|
|
|
(js--ensure-cache)
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cl-assert (or (= (point-min) (point-max))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(eq js--last-parse-pos (point))))
|
|
|
|
|
(when js--last-parse-pos
|
|
|
|
|
(let ((state js--state-at-last-parse-pos)
|
|
|
|
|
(unknown-ctr (cons -1 nil)))
|
|
|
|
|
|
|
|
|
|
;; Make sure everything is closed
|
|
|
|
|
(while (cdr state)
|
|
|
|
|
(setq state
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cons (js--pitem-add-child (cl-second state) (car state))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(cddr state))))
|
|
|
|
|
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cl-assert (= (length state) 1))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
;; Convert the new-finalized state into what imenu expects
|
|
|
|
|
(js--pitems-to-imenu
|
|
|
|
|
(car (js--pitem-children state))
|
|
|
|
|
unknown-ctr))))))
|
|
|
|
|
|
2009-08-15 01:04:14 +00:00
|
|
|
|
;; Silence the compiler.
|
|
|
|
|
(defvar which-func-imenu-joiner-function)
|
|
|
|
|
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(defun js--which-func-joiner (parts)
|
|
|
|
|
(mapconcat #'identity parts "."))
|
|
|
|
|
|
|
|
|
|
(defun js--imenu-to-flat (items prefix symbols)
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cl-loop for item in items
|
|
|
|
|
if (imenu--subalist-p item)
|
|
|
|
|
do (js--imenu-to-flat
|
|
|
|
|
(cdr item) (concat prefix (car item) ".")
|
|
|
|
|
symbols)
|
|
|
|
|
else
|
|
|
|
|
do (let* ((name (concat prefix (car item)))
|
|
|
|
|
(name2 name)
|
|
|
|
|
(ctr 0))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(while (gethash name2 symbols)
|
|
|
|
|
(setq name2 (format "%s<%d>" name (cl-incf ctr))))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(puthash name2 (cdr item) symbols))))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defun js--get-all-known-symbols ()
|
* international/ucs-normalize.el (ucs-normalize-sort, quick-check-list):
Fix typos in docstrings.
* progmodes/js.el (js--macro-decl-re): Doc fix.
(js--plain-method-re, js--split-name): Refloc docstring.
(js--class-styles, js--make-merged-item, js--splice-into-items):
Fix typos in docstrings; reflow docstrings.
(js--maybe-join, js--function-prologue-beginning, js--flush-caches)
(js--variable-decl-matcher, js--inside-pitem-p)
(js--parse-state-at-point, js--get-all-known-symbols)
(js--symbol-history, js-find-symbol, js--js-references)
(js--moz-interactor, js--js-encode-value, js--read-tab):
Fix typos in docstrings.
2009-08-28 18:22:30 +00:00
|
|
|
|
"Return a hash table of all JavaScript symbols.
|
2009-08-15 01:04:14 +00:00
|
|
|
|
This searches all existing `js-mode' buffers. Each key is the
|
|
|
|
|
name of a symbol (possibly disambiguated with <N>, where N > 1),
|
|
|
|
|
and each value is a marker giving the location of that symbol."
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cl-loop with symbols = (make-hash-table :test 'equal)
|
|
|
|
|
with imenu-use-markers = t
|
|
|
|
|
for buffer being the buffers
|
|
|
|
|
for imenu-index = (with-current-buffer buffer
|
|
|
|
|
(when (derived-mode-p 'js-mode)
|
|
|
|
|
(js--imenu-create-index)))
|
|
|
|
|
do (js--imenu-to-flat imenu-index "" symbols)
|
|
|
|
|
finally return symbols))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defvar js--symbol-history nil
|
* international/ucs-normalize.el (ucs-normalize-sort, quick-check-list):
Fix typos in docstrings.
* progmodes/js.el (js--macro-decl-re): Doc fix.
(js--plain-method-re, js--split-name): Refloc docstring.
(js--class-styles, js--make-merged-item, js--splice-into-items):
Fix typos in docstrings; reflow docstrings.
(js--maybe-join, js--function-prologue-beginning, js--flush-caches)
(js--variable-decl-matcher, js--inside-pitem-p)
(js--parse-state-at-point, js--get-all-known-symbols)
(js--symbol-history, js-find-symbol, js--js-references)
(js--moz-interactor, js--js-encode-value, js--read-tab):
Fix typos in docstrings.
2009-08-28 18:22:30 +00:00
|
|
|
|
"History of entered JavaScript symbols.")
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defun js--read-symbol (symbols-table prompt &optional initial-input)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Helper function for `js-find-symbol'.
|
|
|
|
|
Read a symbol from SYMBOLS-TABLE, which is a hash table like the
|
|
|
|
|
one from `js--get-all-known-symbols', using prompt PROMPT and
|
|
|
|
|
initial input INITIAL-INPUT. Return a cons of (SYMBOL-NAME
|
|
|
|
|
. LOCATION), where SYMBOL-NAME is a string and LOCATION is a
|
|
|
|
|
marker."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(unless ido-mode
|
2011-04-22 20:44:26 +02:00
|
|
|
|
(ido-mode 1)
|
|
|
|
|
(ido-mode -1))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(let ((choice (ido-completing-read
|
|
|
|
|
prompt
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cl-loop for key being the hash-keys of symbols-table
|
|
|
|
|
collect key)
|
2009-08-14 23:02:38 +00:00
|
|
|
|
nil t initial-input 'js--symbol-history)))
|
|
|
|
|
(cons choice (gethash choice symbols-table))))
|
|
|
|
|
|
|
|
|
|
(defun js--guess-symbol-at-point ()
|
|
|
|
|
(let ((bounds (bounds-of-thing-at-point 'symbol)))
|
|
|
|
|
(when bounds
|
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char (car bounds))
|
|
|
|
|
(when (eq (char-before) ?.)
|
|
|
|
|
(backward-char)
|
|
|
|
|
(setf (car bounds) (point))))
|
|
|
|
|
(buffer-substring (car bounds) (cdr bounds)))))
|
|
|
|
|
|
2010-12-14 00:06:18 -08:00
|
|
|
|
(defvar find-tag-marker-ring) ; etags
|
|
|
|
|
|
2013-05-23 00:37:56 -07:00
|
|
|
|
;; etags loads ring.
|
|
|
|
|
(declare-function ring-insert "ring" (ring item))
|
|
|
|
|
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(defun js-find-symbol (&optional arg)
|
* international/ucs-normalize.el (ucs-normalize-sort, quick-check-list):
Fix typos in docstrings.
* progmodes/js.el (js--macro-decl-re): Doc fix.
(js--plain-method-re, js--split-name): Refloc docstring.
(js--class-styles, js--make-merged-item, js--splice-into-items):
Fix typos in docstrings; reflow docstrings.
(js--maybe-join, js--function-prologue-beginning, js--flush-caches)
(js--variable-decl-matcher, js--inside-pitem-p)
(js--parse-state-at-point, js--get-all-known-symbols)
(js--symbol-history, js-find-symbol, js--js-references)
(js--moz-interactor, js--js-encode-value, js--read-tab):
Fix typos in docstrings.
2009-08-28 18:22:30 +00:00
|
|
|
|
"Read a JavaScript symbol and jump to it.
|
2009-08-15 01:04:14 +00:00
|
|
|
|
With a prefix argument, restrict symbols to those from the
|
* international/ucs-normalize.el (ucs-normalize-sort, quick-check-list):
Fix typos in docstrings.
* progmodes/js.el (js--macro-decl-re): Doc fix.
(js--plain-method-re, js--split-name): Refloc docstring.
(js--class-styles, js--make-merged-item, js--splice-into-items):
Fix typos in docstrings; reflow docstrings.
(js--maybe-join, js--function-prologue-beginning, js--flush-caches)
(js--variable-decl-matcher, js--inside-pitem-p)
(js--parse-state-at-point, js--get-all-known-symbols)
(js--symbol-history, js-find-symbol, js--js-references)
(js--moz-interactor, js--js-encode-value, js--read-tab):
Fix typos in docstrings.
2009-08-28 18:22:30 +00:00
|
|
|
|
current buffer. Pushes a mark onto the tag ring just like
|
2009-08-15 01:04:14 +00:00
|
|
|
|
`find-tag'."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(interactive "P")
|
2010-12-14 00:06:18 -08:00
|
|
|
|
(require 'etags)
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(let (symbols marker)
|
|
|
|
|
(if (not arg)
|
|
|
|
|
(setq symbols (js--get-all-known-symbols))
|
|
|
|
|
(setq symbols (make-hash-table :test 'equal))
|
|
|
|
|
(js--imenu-to-flat (js--imenu-create-index)
|
|
|
|
|
"" symbols))
|
|
|
|
|
|
|
|
|
|
(setq marker (cdr (js--read-symbol
|
|
|
|
|
symbols "Jump to: "
|
|
|
|
|
(js--guess-symbol-at-point))))
|
|
|
|
|
|
|
|
|
|
(ring-insert find-tag-marker-ring (point-marker))
|
|
|
|
|
(switch-to-buffer (marker-buffer marker))
|
|
|
|
|
(push-mark)
|
|
|
|
|
(goto-char marker)))
|
|
|
|
|
|
|
|
|
|
;;; MozRepl integration
|
|
|
|
|
|
* lisp/subr.el (define-error): New function.
* doc/lispref/control.texi (Signaling Errors): Refer to define-error.
(Error Symbols): Add `define-error'.
* doc/lispref/errors.texi (Standard Errors): Don't refer to `error-conditions'.
* lisp/progmodes/ada-xref.el (ada-error-file-not-found): Rename from
error-file-not-found and define with define-error.
* lisp/emacs-lisp/cl-lib.el (cl-assertion-failed): Move here from subr.el
and define with define-error.
* lisp/userlock.el (file-locked, file-supersession):
* lisp/simple.el (mark-inactive):
* lisp/progmodes/js.el (js-moz-bad-rpc, js-js-error):
* lisp/progmodes/ada-mode.el (ada-mode-errors):
* lisp/play/life.el (life-extinct):
* lisp/nxml/xsd-regexp.el (xsdre-invalid-regexp, xsdre-parse-error):
* lisp/nxml/xmltok.el (xmltok-markup-declaration-parse-error):
* lisp/nxml/rng-util.el (rng-error):
* lisp/nxml/rng-uri.el (rng-uri-error):
* lisp/nxml/rng-match.el (rng-compile-error):
* lisp/nxml/rng-cmpct.el (rng-c-incorrect-schema):
* lisp/nxml/nxml-util.el (nxml-error, nxml-file-parse-error):
* lisp/nxml/nxml-rap.el (nxml-scan-error):
* lisp/nxml/nxml-outln.el (nxml-outline-error):
* lisp/net/soap-client.el (soap-error):
* lisp/net/gnutls.el (gnutls-error):
* lisp/net/ange-ftp.el (ftp-error):
* lisp/mpc.el (mpc-proc-error):
* lisp/json.el (json-error, json-readtable-error, json-unknown-keyword)
(json-number-format, json-string-escape, json-string-format)
(json-key-format, json-object-format):
* lisp/jka-compr.el (compression-error):
* lisp/international/quail.el (quail-error):
* lisp/international/kkc.el (kkc-error):
* lisp/emacs-lisp/ert.el (ert-test-failed):
* lisp/calc/calc.el (calc-error, inexact-result, math-overflow)
(math-underflow):
* lisp/bookmark.el (bookmark-error-no-filename):
* lisp/epg.el (epg-error): Define with define-error.
2013-08-09 17:22:44 -04:00
|
|
|
|
(define-error 'js-moz-bad-rpc "Mozilla RPC Error") ;; '(timeout error))
|
2017-01-29 10:39:55 +02:00
|
|
|
|
(define-error 'js-js-error "JavaScript Error") ;; '(js-error error))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defun js--wait-for-matching-output
|
|
|
|
|
(process regexp timeout &optional start)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Wait TIMEOUT seconds for PROCESS to output a match for REGEXP.
|
|
|
|
|
On timeout, return nil. On success, return t with match data
|
|
|
|
|
set. If START is non-nil, look for output starting from START.
|
|
|
|
|
Otherwise, use the current value of `process-mark'."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(with-current-buffer (process-buffer process)
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cl-loop with start-pos = (or start
|
|
|
|
|
(marker-position (process-mark process)))
|
Avoid some double-rounding of Lisp timestamps
Also, simplify some time-related Lisp timestamp code
while we’re in the neighborhood.
* lisp/battery.el (battery-linux-proc-acpi)
(battery-linux-sysfs, battery-upower, battery-bsd-apm):
* lisp/calendar/timeclock.el (timeclock-seconds-to-string)
(timeclock-log, timeclock-last-period)
(timeclock-entry-length, timeclock-entry-list-span)
(timeclock-find-discrep, timeclock-generate-report):
* lisp/cedet/ede/detect.el (ede-detect-qtest):
* lisp/completion.el (cmpl-hours-since-origin):
* lisp/ecomplete.el (ecomplete-decay-1):
* lisp/emacs-lisp/ert.el (ert--results-update-stats-display)
(ert--results-update-stats-display-maybe):
* lisp/emacs-lisp/timer-list.el (list-timers):
* lisp/emacs-lisp/timer.el (timer-until)
(timer-event-handler):
* lisp/erc/erc-backend.el (erc-server-send-ping)
(erc-server-send-queue, erc-handle-parsed-server-response)
(erc-handle-unknown-server-response):
* lisp/erc/erc-track.el (erc-buffer-visible):
* lisp/erc/erc.el (erc-lurker-cleanup, erc-lurker-p)
(erc-cmd-PING, erc-send-current-line):
* lisp/eshell/em-pred.el (eshell-pred-file-time):
* lisp/eshell/em-unix.el (eshell-show-elapsed-time):
* lisp/gnus/gnus-icalendar.el (gnus-icalendar-event:org-timestamp):
* lisp/gnus/gnus-int.el (gnus-backend-trace):
* lisp/gnus/gnus-sum.el (gnus-user-date):
* lisp/gnus/mail-source.el (mail-source-delete-crash-box):
* lisp/gnus/nnmaildir.el (nnmaildir--scan):
* lisp/ibuf-ext.el (ibuffer-mark-old-buffers):
* lisp/gnus/nnmaildir.el (nnmaildir--scan):
* lisp/mouse.el (mouse--down-1-maybe-follows-link)
(mouse--click-1-maybe-follows-link):
* lisp/mpc.el (mpc--faster-toggle):
* lisp/net/rcirc.el (rcirc-handler-ctcp-KEEPALIVE)
(rcirc-sentinel):
* lisp/net/tramp-cache.el (tramp-get-file-property):
* lisp/net/tramp-sh.el (tramp-sh-handle-file-newer-than-file-p)
(tramp-maybe-open-connection):
* lisp/net/tramp-smb.el (tramp-smb-maybe-open-connection):
* lisp/org/org-clock.el (org-clock-resolve):
(org-resolve-clocks, org-clock-in, org-clock-out, org-clock-sum):
* lisp/org/org-timer.el (org-timer-start)
(org-timer-pause-or-continue, org-timer-seconds):
* lisp/org/org.el (org-evaluate-time-range):
* lisp/org/ox-publish.el (org-publish-cache-ctime-of-src):
* lisp/pixel-scroll.el (pixel-scroll-in-rush-p):
* lisp/play/hanoi.el (hanoi-move-ring):
* lisp/proced.el (proced-format-time):
* lisp/progmodes/cpp.el (cpp-progress-message):
* lisp/progmodes/flymake.el (flymake--handle-report):
* lisp/progmodes/js.el (js--wait-for-matching-output):
* lisp/subr.el (progress-reporter-do-update):
* lisp/term/xterm.el (xterm--read-event-for-query):
* lisp/time.el (display-time-update, emacs-uptime):
* lisp/tooltip.el (tooltip-delay):
* lisp/url/url-cookie.el (url-cookie-parse-file-netscape):
* lisp/url/url-queue.el (url-queue-prune-old-entries):
* lisp/url/url.el (url-retrieve-synchronously):
* lisp/xt-mouse.el (xterm-mouse-event):
Avoid double-rounding of time-related values. Simplify.
* lisp/calendar/icalendar.el (icalendar--decode-isodatetime):
When hoping for the best (unlikely), use a better decoded time.
(icalendar--convert-sexp-to-ical): Avoid unnecessary encode-time.
* lisp/calendar/timeclock.el (timeclock-when-to-leave):
* lisp/cedet/ede/detect.el (ede-detect-qtest):
* lisp/desktop.el (desktop-create-buffer):
* lisp/emacs-lisp/benchmark.el (benchmark-elapse):
* lisp/gnus/gnus-art.el (article-lapsed-string):
* lisp/gnus/gnus-group.el (gnus-group-timestamp-delta):
* lisp/gnus/nnmail.el (nnmail-expired-article-p):
* lisp/gnus/nnmaildir.el (nnmaildir-request-expire-articles):
* lisp/nxml/rng-maint.el (rng-time-function):
* lisp/org/org-clock.el (org-clock-get-clocked-time)
(org-clock-resolve, org-resolve-clocks, org-resolve-clocks-if-idle):
* lisp/org/org-habit.el (org-habit-insert-consistency-graphs):
* lisp/progmodes/vhdl-mode.el (vhdl-update-progress-info)
(vhdl-fix-case-region-1):
Use time-since instead of open-coding most of it.
* lisp/erc/erc-dcc.el (erc-dcc-get-sentinel):
* lisp/erc/erc.el (erc-string-to-emacs-time, erc-time-gt):
Now obsolete. All uses changed.
(erc-time-diff): Accept all Lisp time values.
All uses changed.
* lisp/gnus/gnus-demon.el (gnus-demon-idle-since):
* lisp/gnus/gnus-score.el (gnus-score-headers):
* lisp/gnus/nneething.el (nneething-make-head):
* lisp/gnus/nnheader.el (nnheader-message-maybe):
* lisp/gnus/nnimap.el (nnimap-keepalive):
* lisp/image.el (image-animate-timeout):
* lisp/mail/feedmail.el (feedmail-rfc822-date):
* lisp/net/imap.el (imap-wait-for-tag):
* lisp/net/newst-backend.el (newsticker--image-get):
* lisp/net/rcirc.el (rcirc-handler-317, rcirc-handler-333):
* lisp/obsolete/xesam.el (xesam-refresh-entry):
* lisp/org/org-agenda.el (org-agenda-show-clocking-issues)
(org-agenda-check-clock-gap, org-agenda-to-appt):
* lisp/org/org-capture.el (org-capture-set-target-location):
* lisp/org/org-clock.el (org-clock-resolve-clock)
(org-clocktable-steps):
* lisp/org/org-colview.el (org-columns-edit-value)
(org-columns, org-agenda-columns):
* lisp/org/org-duration.el (org-duration-from-minutes):
* lisp/org/org-element.el (org-element-cache-sync-duration)
(org-element-cache-sync-break)
(org-element--cache-interrupt-p, org-element--cache-sync):
* lisp/org/org-habit.el (org-habit-get-faces)
* lisp/org/org-indent.el (org-indent-add-properties):
* lisp/org/org-table.el (org-table-sum):
* lisp/org/org-timer.el (org-timer-show-remaining-time)
(org-timer-set-timer):
* lisp/org/org.el (org-babel-load-file, org-today)
(org-auto-repeat-maybe, org-2ft, org-time-stamp)
(org-read-date-analyze, org-time-stamp-to-now)
(org-small-year-to-year, org-goto-calendar):
* lisp/org/ox.el (org-export-insert-default-template):
* lisp/ses.el (ses--time-check):
* lisp/type-break.el (type-break-time-warning)
(type-break-statistics, type-break-demo-boring):
* lisp/url/url-cache.el (url-cache-expired)
(url-cache-prune-cache):
* lisp/vc/vc-git.el (vc-git-stash-snapshot):
* lisp/erc/erc-match.el (erc-log-matches-come-back):
Simplify.
2019-02-22 18:32:31 -08:00
|
|
|
|
with end-time = (time-add nil timeout)
|
|
|
|
|
for time-left = (float-time (time-subtract end-time nil))
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
do (goto-char (point-max))
|
|
|
|
|
if (looking-back regexp start-pos) return t
|
|
|
|
|
while (> time-left 0)
|
|
|
|
|
do (accept-process-output process time-left nil t)
|
|
|
|
|
do (goto-char (process-mark process))
|
|
|
|
|
finally do (signal
|
|
|
|
|
'js-moz-bad-rpc
|
|
|
|
|
(list (format "Timed out waiting for output matching %S" regexp))))))
|
|
|
|
|
|
|
|
|
|
(cl-defstruct js--js-handle
|
2009-08-14 23:02:38 +00:00
|
|
|
|
;; Integer, mirrors the value we see in JS
|
|
|
|
|
(id nil :read-only t)
|
|
|
|
|
|
|
|
|
|
;; Process to which this thing belongs
|
|
|
|
|
(process nil :read-only t))
|
|
|
|
|
|
|
|
|
|
(defun js--js-handle-expired-p (x)
|
|
|
|
|
(not (eq (js--js-handle-process x)
|
|
|
|
|
(inferior-moz-process))))
|
|
|
|
|
|
|
|
|
|
(defvar js--js-references nil
|
* international/ucs-normalize.el (ucs-normalize-sort, quick-check-list):
Fix typos in docstrings.
* progmodes/js.el (js--macro-decl-re): Doc fix.
(js--plain-method-re, js--split-name): Refloc docstring.
(js--class-styles, js--make-merged-item, js--splice-into-items):
Fix typos in docstrings; reflow docstrings.
(js--maybe-join, js--function-prologue-beginning, js--flush-caches)
(js--variable-decl-matcher, js--inside-pitem-p)
(js--parse-state-at-point, js--get-all-known-symbols)
(js--symbol-history, js-find-symbol, js--js-references)
(js--moz-interactor, js--js-encode-value, js--read-tab):
Fix typos in docstrings.
2009-08-28 18:22:30 +00:00
|
|
|
|
"Maps Elisp JavaScript proxy objects to their JavaScript IDs.")
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defvar js--js-process nil
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"The most recent MozRepl process object.")
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defvar js--js-gc-idle-timer nil
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Idle timer for cleaning up JS object references.")
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
2009-08-15 01:04:14 +00:00
|
|
|
|
(defvar js--js-last-gcs-done nil)
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defconst js--moz-interactor
|
|
|
|
|
(replace-regexp-in-string
|
|
|
|
|
"[ \n]+" " "
|
|
|
|
|
; */" Make Emacs happy
|
|
|
|
|
"(function(repl) {
|
|
|
|
|
repl.defineInteractor('js', {
|
|
|
|
|
onStart: function onStart(repl) {
|
|
|
|
|
if(!repl._jsObjects) {
|
|
|
|
|
repl._jsObjects = {};
|
|
|
|
|
repl._jsLastID = 0;
|
|
|
|
|
repl._jsGC = this._jsGC;
|
|
|
|
|
}
|
|
|
|
|
this._input = '';
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_jsGC: function _jsGC(ids_in_use) {
|
|
|
|
|
var objects = this._jsObjects;
|
|
|
|
|
var keys = [];
|
|
|
|
|
var num_freed = 0;
|
|
|
|
|
|
|
|
|
|
for(var pn in objects) {
|
|
|
|
|
keys.push(Number(pn));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
keys.sort(function(x, y) x - y);
|
|
|
|
|
ids_in_use.sort(function(x, y) x - y);
|
|
|
|
|
var i = 0;
|
|
|
|
|
var j = 0;
|
|
|
|
|
|
|
|
|
|
while(i < ids_in_use.length && j < keys.length) {
|
|
|
|
|
var id = ids_in_use[i++];
|
|
|
|
|
while(j < keys.length && keys[j] !== id) {
|
|
|
|
|
var k_id = keys[j++];
|
|
|
|
|
delete objects[k_id];
|
|
|
|
|
++num_freed;
|
|
|
|
|
}
|
|
|
|
|
++j;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while(j < keys.length) {
|
|
|
|
|
var k_id = keys[j++];
|
|
|
|
|
delete objects[k_id];
|
|
|
|
|
++num_freed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return num_freed;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_mkArray: function _mkArray() {
|
|
|
|
|
var result = [];
|
|
|
|
|
for(var i = 0; i < arguments.length; ++i) {
|
|
|
|
|
result.push(arguments[i]);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_parsePropDescriptor: function _parsePropDescriptor(parts) {
|
|
|
|
|
if(typeof parts === 'string') {
|
|
|
|
|
parts = [ parts ];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var obj = parts[0];
|
|
|
|
|
var start = 1;
|
|
|
|
|
|
|
|
|
|
if(typeof obj === 'string') {
|
|
|
|
|
obj = window;
|
|
|
|
|
start = 0;
|
|
|
|
|
} else if(parts.length < 2) {
|
|
|
|
|
throw new Error('expected at least 2 arguments');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(var i = start; i < parts.length - 1; ++i) {
|
|
|
|
|
obj = obj[parts[i]];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return [obj, parts[parts.length - 1]];
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_getProp: function _getProp(/*...*/) {
|
|
|
|
|
if(arguments.length === 0) {
|
|
|
|
|
throw new Error('no arguments supplied to getprop');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(arguments.length === 1 &&
|
|
|
|
|
(typeof arguments[0]) !== 'string')
|
|
|
|
|
{
|
|
|
|
|
return arguments[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var [obj, propname] = this._parsePropDescriptor(arguments);
|
|
|
|
|
return obj[propname];
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_putProp: function _putProp(properties, value) {
|
|
|
|
|
var [obj, propname] = this._parsePropDescriptor(properties);
|
|
|
|
|
obj[propname] = value;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_delProp: function _delProp(propname) {
|
|
|
|
|
var [obj, propname] = this._parsePropDescriptor(arguments);
|
|
|
|
|
delete obj[propname];
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_typeOf: function _typeOf(thing) {
|
|
|
|
|
return typeof thing;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_callNew: function(constructor) {
|
|
|
|
|
if(typeof constructor === 'string')
|
|
|
|
|
{
|
|
|
|
|
constructor = window[constructor];
|
|
|
|
|
} else if(constructor.length === 1 &&
|
|
|
|
|
typeof constructor[0] !== 'string')
|
|
|
|
|
{
|
|
|
|
|
constructor = constructor[0];
|
|
|
|
|
} else {
|
|
|
|
|
var [obj,propname] = this._parsePropDescriptor(constructor);
|
|
|
|
|
constructor = obj[propname];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Hacky, but should be robust */
|
|
|
|
|
var s = 'new constructor(';
|
|
|
|
|
for(var i = 1; i < arguments.length; ++i) {
|
|
|
|
|
if(i != 1) {
|
|
|
|
|
s += ',';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s += 'arguments[' + i + ']';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s += ')';
|
|
|
|
|
return eval(s);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_callEval: function(thisobj, js) {
|
|
|
|
|
return eval.call(thisobj, js);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getPrompt: function getPrompt(repl) {
|
|
|
|
|
return 'EVAL>'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_lookupObject: function _lookupObject(repl, id) {
|
|
|
|
|
if(typeof id === 'string') {
|
|
|
|
|
switch(id) {
|
|
|
|
|
case 'global':
|
|
|
|
|
return window;
|
|
|
|
|
case 'nil':
|
|
|
|
|
return null;
|
|
|
|
|
case 't':
|
|
|
|
|
return true;
|
|
|
|
|
case 'false':
|
|
|
|
|
return false;
|
|
|
|
|
case 'undefined':
|
|
|
|
|
return undefined;
|
|
|
|
|
case 'repl':
|
|
|
|
|
return repl;
|
|
|
|
|
case 'interactor':
|
|
|
|
|
return this;
|
|
|
|
|
case 'NaN':
|
|
|
|
|
return NaN;
|
|
|
|
|
case 'Infinity':
|
|
|
|
|
return Infinity;
|
|
|
|
|
case '-Infinity':
|
|
|
|
|
return -Infinity;
|
|
|
|
|
default:
|
|
|
|
|
throw new Error('No object with special id:' + id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var ret = repl._jsObjects[id];
|
|
|
|
|
if(ret === undefined) {
|
|
|
|
|
throw new Error('No object with id:' + id + '(' + typeof id + ')');
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_findOrAllocateObject: function _findOrAllocateObject(repl, value) {
|
|
|
|
|
if(typeof value !== 'object' && typeof value !== 'function') {
|
|
|
|
|
throw new Error('_findOrAllocateObject called on non-object('
|
|
|
|
|
+ typeof(value) + '): '
|
|
|
|
|
+ value)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(var id in repl._jsObjects) {
|
|
|
|
|
id = Number(id);
|
|
|
|
|
var obj = repl._jsObjects[id];
|
|
|
|
|
if(obj === value) {
|
|
|
|
|
return id;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var id = ++repl._jsLastID;
|
|
|
|
|
repl._jsObjects[id] = value;
|
|
|
|
|
return id;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_fixupList: function _fixupList(repl, list) {
|
|
|
|
|
for(var i = 0; i < list.length; ++i) {
|
|
|
|
|
if(list[i] instanceof Array) {
|
|
|
|
|
this._fixupList(repl, list[i]);
|
|
|
|
|
} else if(typeof list[i] === 'object') {
|
|
|
|
|
var obj = list[i];
|
|
|
|
|
if(obj.funcall) {
|
|
|
|
|
var parts = obj.funcall;
|
|
|
|
|
this._fixupList(repl, parts);
|
|
|
|
|
var [thisobj, func] = this._parseFunc(parts[0]);
|
|
|
|
|
list[i] = func.apply(thisobj, parts.slice(1));
|
|
|
|
|
} else if(obj.objid) {
|
|
|
|
|
list[i] = this._lookupObject(repl, obj.objid);
|
|
|
|
|
} else {
|
|
|
|
|
throw new Error('Unknown object type: ' + obj.toSource());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_parseFunc: function(func) {
|
|
|
|
|
var thisobj = null;
|
|
|
|
|
|
|
|
|
|
if(typeof func === 'string') {
|
|
|
|
|
func = window[func];
|
|
|
|
|
} else if(func instanceof Array) {
|
|
|
|
|
if(func.length === 1 && typeof func[0] !== 'string') {
|
|
|
|
|
func = func[0];
|
|
|
|
|
} else {
|
|
|
|
|
[thisobj, func] = this._parsePropDescriptor(func);
|
|
|
|
|
func = thisobj[func];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return [thisobj,func];
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_encodeReturn: function(value, array_as_mv) {
|
|
|
|
|
var ret;
|
|
|
|
|
|
|
|
|
|
if(value === null) {
|
|
|
|
|
ret = ['special', 'null'];
|
|
|
|
|
} else if(value === true) {
|
|
|
|
|
ret = ['special', 'true'];
|
|
|
|
|
} else if(value === false) {
|
|
|
|
|
ret = ['special', 'false'];
|
|
|
|
|
} else if(value === undefined) {
|
|
|
|
|
ret = ['special', 'undefined'];
|
|
|
|
|
} else if(typeof value === 'number') {
|
|
|
|
|
if(isNaN(value)) {
|
|
|
|
|
ret = ['special', 'NaN'];
|
|
|
|
|
} else if(value === Infinity) {
|
|
|
|
|
ret = ['special', 'Infinity'];
|
|
|
|
|
} else if(value === -Infinity) {
|
|
|
|
|
ret = ['special', '-Infinity'];
|
|
|
|
|
} else {
|
|
|
|
|
ret = ['atom', value];
|
|
|
|
|
}
|
|
|
|
|
} else if(typeof value === 'string') {
|
|
|
|
|
ret = ['atom', value];
|
|
|
|
|
} else if(array_as_mv && value instanceof Array) {
|
|
|
|
|
ret = ['array', value.map(this._encodeReturn, this)];
|
|
|
|
|
} else {
|
|
|
|
|
ret = ['objid', this._findOrAllocateObject(repl, value)];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_handleInputLine: function _handleInputLine(repl, line) {
|
|
|
|
|
var ret;
|
|
|
|
|
var array_as_mv = false;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if(line[0] === '*') {
|
|
|
|
|
array_as_mv = true;
|
|
|
|
|
line = line.substring(1);
|
|
|
|
|
}
|
|
|
|
|
var parts = eval(line);
|
|
|
|
|
this._fixupList(repl, parts);
|
|
|
|
|
var [thisobj, func] = this._parseFunc(parts[0]);
|
|
|
|
|
ret = this._encodeReturn(
|
|
|
|
|
func.apply(thisobj, parts.slice(1)),
|
|
|
|
|
array_as_mv);
|
|
|
|
|
} catch(x) {
|
|
|
|
|
ret = ['error', x.toString() ];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var JSON = Components.classes['@mozilla.org/dom/json;1'].createInstance(Components.interfaces.nsIJSON);
|
|
|
|
|
repl.print(JSON.encode(ret));
|
|
|
|
|
repl._prompt();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
handleInput: function handleInput(repl, chunk) {
|
|
|
|
|
this._input += chunk;
|
|
|
|
|
var match, line;
|
|
|
|
|
while(match = this._input.match(/.*\\n/)) {
|
|
|
|
|
line = match[0];
|
|
|
|
|
|
|
|
|
|
if(line === 'EXIT\\n') {
|
|
|
|
|
repl.popInteractor();
|
|
|
|
|
repl._prompt();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this._input = this._input.substring(line.length);
|
|
|
|
|
this._handleInputLine(repl, line);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
")
|
|
|
|
|
|
* international/ucs-normalize.el (ucs-normalize-sort, quick-check-list):
Fix typos in docstrings.
* progmodes/js.el (js--macro-decl-re): Doc fix.
(js--plain-method-re, js--split-name): Refloc docstring.
(js--class-styles, js--make-merged-item, js--splice-into-items):
Fix typos in docstrings; reflow docstrings.
(js--maybe-join, js--function-prologue-beginning, js--flush-caches)
(js--variable-decl-matcher, js--inside-pitem-p)
(js--parse-state-at-point, js--get-all-known-symbols)
(js--symbol-history, js-find-symbol, js--js-references)
(js--moz-interactor, js--js-encode-value, js--read-tab):
Fix typos in docstrings.
2009-08-28 18:22:30 +00:00
|
|
|
|
"String to set MozRepl up into a simple-minded evaluation mode.")
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defun js--js-encode-value (x)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Marshall the given value for JS.
|
|
|
|
|
Strings and numbers are JSON-encoded. Lists (including nil) are
|
* international/ucs-normalize.el (ucs-normalize-sort, quick-check-list):
Fix typos in docstrings.
* progmodes/js.el (js--macro-decl-re): Doc fix.
(js--plain-method-re, js--split-name): Refloc docstring.
(js--class-styles, js--make-merged-item, js--splice-into-items):
Fix typos in docstrings; reflow docstrings.
(js--maybe-join, js--function-prologue-beginning, js--flush-caches)
(js--variable-decl-matcher, js--inside-pitem-p)
(js--parse-state-at-point, js--get-all-known-symbols)
(js--symbol-history, js-find-symbol, js--js-references)
(js--moz-interactor, js--js-encode-value, js--read-tab):
Fix typos in docstrings.
2009-08-28 18:22:30 +00:00
|
|
|
|
made into JavaScript array literals and their contents encoded
|
2009-08-15 01:04:14 +00:00
|
|
|
|
with `js--js-encode-value'."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(cond ((stringp x) (json-encode-string x))
|
|
|
|
|
((numberp x) (json-encode-number x))
|
|
|
|
|
((symbolp x) (format "{objid:%S}" (symbol-name x)))
|
|
|
|
|
((js--js-handle-p x)
|
|
|
|
|
|
|
|
|
|
(when (js--js-handle-expired-p x)
|
|
|
|
|
(error "Stale JS handle"))
|
|
|
|
|
|
|
|
|
|
(format "{objid:%s}" (js--js-handle-id x)))
|
|
|
|
|
|
|
|
|
|
((sequencep x)
|
|
|
|
|
(if (eq (car-safe x) 'js--funcall)
|
|
|
|
|
(format "{funcall:[%s]}"
|
|
|
|
|
(mapconcat #'js--js-encode-value (cdr x) ","))
|
|
|
|
|
(concat
|
|
|
|
|
"[" (mapconcat #'js--js-encode-value x ",") "]")))
|
|
|
|
|
(t
|
|
|
|
|
(error "Unrecognized item: %S" x))))
|
|
|
|
|
|
|
|
|
|
(defconst js--js-prompt-regexp "\\(repl[0-9]*\\)> $")
|
|
|
|
|
(defconst js--js-repl-prompt-regexp "^EVAL>$")
|
|
|
|
|
(defvar js--js-repl-depth 0)
|
|
|
|
|
|
|
|
|
|
(defun js--js-wait-for-eval-prompt ()
|
|
|
|
|
(js--wait-for-matching-output
|
|
|
|
|
(inferior-moz-process)
|
|
|
|
|
js--js-repl-prompt-regexp js-js-timeout
|
|
|
|
|
|
|
|
|
|
;; start matching against the beginning of the line in
|
|
|
|
|
;; order to catch a prompt that's only partially arrived
|
|
|
|
|
(save-excursion (forward-line 0) (point))))
|
|
|
|
|
|
2013-05-23 00:37:56 -07:00
|
|
|
|
;; Presumably "inferior-moz-process" loads comint.
|
|
|
|
|
(declare-function comint-send-string "comint" (process string))
|
|
|
|
|
(declare-function comint-send-input "comint"
|
|
|
|
|
(&optional no-newline artificial))
|
|
|
|
|
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(defun js--js-enter-repl ()
|
|
|
|
|
(inferior-moz-process) ; called for side-effect
|
|
|
|
|
(with-current-buffer inferior-moz-buffer
|
|
|
|
|
(goto-char (point-max))
|
|
|
|
|
|
|
|
|
|
;; Do some initialization the first time we see a process
|
|
|
|
|
(unless (eq (inferior-moz-process) js--js-process)
|
|
|
|
|
(setq js--js-process (inferior-moz-process))
|
|
|
|
|
(setq js--js-references (make-hash-table :test 'eq :weakness t))
|
|
|
|
|
(setq js--js-repl-depth 0)
|
|
|
|
|
|
|
|
|
|
;; Send interactor definition
|
|
|
|
|
(comint-send-string js--js-process js--moz-interactor)
|
|
|
|
|
(comint-send-string js--js-process
|
|
|
|
|
(concat "(" moz-repl-name ")\n"))
|
|
|
|
|
(js--wait-for-matching-output
|
|
|
|
|
(inferior-moz-process) js--js-prompt-regexp
|
|
|
|
|
js-js-timeout))
|
|
|
|
|
|
|
|
|
|
;; Sanity check
|
|
|
|
|
(when (looking-back js--js-prompt-regexp
|
|
|
|
|
(save-excursion (forward-line 0) (point)))
|
|
|
|
|
(setq js--js-repl-depth 0))
|
|
|
|
|
|
|
|
|
|
(if (> js--js-repl-depth 0)
|
|
|
|
|
;; If js--js-repl-depth > 0, we *should* be seeing an
|
|
|
|
|
;; EVAL> prompt. If we don't, give Mozilla a chance to catch
|
|
|
|
|
;; up with us.
|
|
|
|
|
(js--js-wait-for-eval-prompt)
|
|
|
|
|
|
|
|
|
|
;; Otherwise, tell Mozilla to enter the interactor mode
|
|
|
|
|
(insert (match-string-no-properties 1)
|
|
|
|
|
".pushInteractor('js')")
|
|
|
|
|
(comint-send-input nil t)
|
|
|
|
|
(js--wait-for-matching-output
|
|
|
|
|
(inferior-moz-process) js--js-repl-prompt-regexp
|
|
|
|
|
js-js-timeout))
|
|
|
|
|
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cl-incf js--js-repl-depth)))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defun js--js-leave-repl ()
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cl-assert (> js--js-repl-depth 0))
|
|
|
|
|
(when (= 0 (cl-decf js--js-repl-depth))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(with-current-buffer inferior-moz-buffer
|
|
|
|
|
(goto-char (point-max))
|
|
|
|
|
(js--js-wait-for-eval-prompt)
|
|
|
|
|
(insert "EXIT")
|
|
|
|
|
(comint-send-input nil t)
|
|
|
|
|
(js--wait-for-matching-output
|
|
|
|
|
(inferior-moz-process) js--js-prompt-regexp
|
|
|
|
|
js-js-timeout))))
|
|
|
|
|
|
|
|
|
|
(defsubst js--js-not (value)
|
2009-12-06 15:34:59 +00:00
|
|
|
|
(memq value '(nil null false undefined)))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defsubst js--js-true (value)
|
|
|
|
|
(not (js--js-not value)))
|
|
|
|
|
|
|
|
|
|
(eval-and-compile
|
|
|
|
|
(defun js--optimize-arglist (arglist)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Convert immediate js< and js! references to deferred ones."
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cl-loop for item in arglist
|
|
|
|
|
if (eq (car-safe item) 'js<)
|
|
|
|
|
collect (append (list 'list ''js--funcall
|
|
|
|
|
'(list 'interactor "_getProp"))
|
|
|
|
|
(js--optimize-arglist (cdr item)))
|
|
|
|
|
else if (eq (car-safe item) 'js>)
|
|
|
|
|
collect (append (list 'list ''js--funcall
|
|
|
|
|
'(list 'interactor "_putProp"))
|
|
|
|
|
|
|
|
|
|
(if (atom (cadr item))
|
|
|
|
|
(list (cadr item))
|
|
|
|
|
(list
|
|
|
|
|
(append
|
|
|
|
|
(list 'list ''js--funcall
|
|
|
|
|
'(list 'interactor "_mkArray"))
|
|
|
|
|
(js--optimize-arglist (cadr item)))))
|
|
|
|
|
(js--optimize-arglist (cddr item)))
|
|
|
|
|
else if (eq (car-safe item) 'js!)
|
|
|
|
|
collect (pcase-let ((`(,_ ,function . ,body) item))
|
|
|
|
|
(append (list 'list ''js--funcall
|
|
|
|
|
(if (consp function)
|
|
|
|
|
(cons 'list
|
|
|
|
|
(js--optimize-arglist function))
|
|
|
|
|
function))
|
|
|
|
|
(js--optimize-arglist body)))
|
|
|
|
|
else
|
|
|
|
|
collect item)))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defmacro js--js-get-service (class-name interface-name)
|
|
|
|
|
`(js! ("Components" "classes" ,class-name "getService")
|
|
|
|
|
(js< "Components" "interfaces" ,interface-name)))
|
|
|
|
|
|
|
|
|
|
(defmacro js--js-create-instance (class-name interface-name)
|
|
|
|
|
`(js! ("Components" "classes" ,class-name "createInstance")
|
|
|
|
|
(js< "Components" "interfaces" ,interface-name)))
|
|
|
|
|
|
|
|
|
|
(defmacro js--js-qi (object interface-name)
|
|
|
|
|
`(js! (,object "QueryInterface")
|
|
|
|
|
(js< "Components" "interfaces" ,interface-name)))
|
|
|
|
|
|
|
|
|
|
(defmacro with-js (&rest forms)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Run FORMS with the Mozilla repl set up for js commands.
|
2009-08-14 23:02:38 +00:00
|
|
|
|
Inside the lexical scope of `with-js', `js?', `js!',
|
|
|
|
|
`js-new', `js-eval', `js-list', `js<', `js>', `js-get-service',
|
|
|
|
|
`js-create-instance', and `js-qi' are defined."
|
2017-01-25 21:34:46 -05:00
|
|
|
|
(declare (indent 0) (debug t))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
`(progn
|
|
|
|
|
(js--js-enter-repl)
|
|
|
|
|
(unwind-protect
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cl-macrolet ((js? (&rest body) `(js--js-true ,@body))
|
|
|
|
|
(js! (function &rest body)
|
|
|
|
|
`(js--js-funcall
|
2009-08-14 23:02:38 +00:00
|
|
|
|
,(if (consp function)
|
|
|
|
|
(cons 'list
|
|
|
|
|
(js--optimize-arglist function))
|
|
|
|
|
function)
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
,@(js--optimize-arglist body)))
|
|
|
|
|
|
|
|
|
|
(js-new (function &rest body)
|
|
|
|
|
`(js--js-new
|
|
|
|
|
,(if (consp function)
|
|
|
|
|
(cons 'list
|
|
|
|
|
(js--optimize-arglist function))
|
|
|
|
|
function)
|
|
|
|
|
,@body))
|
|
|
|
|
|
|
|
|
|
(js-eval (thisobj js)
|
|
|
|
|
`(js--js-eval
|
|
|
|
|
,@(js--optimize-arglist
|
|
|
|
|
(list thisobj js))))
|
|
|
|
|
|
|
|
|
|
(js-list (&rest args)
|
|
|
|
|
`(js--js-list
|
|
|
|
|
,@(js--optimize-arglist args)))
|
|
|
|
|
|
|
|
|
|
(js-get-service (&rest args)
|
|
|
|
|
`(js--js-get-service
|
|
|
|
|
,@(js--optimize-arglist args)))
|
|
|
|
|
|
|
|
|
|
(js-create-instance (&rest args)
|
|
|
|
|
`(js--js-create-instance
|
|
|
|
|
,@(js--optimize-arglist args)))
|
|
|
|
|
|
|
|
|
|
(js-qi (&rest args)
|
|
|
|
|
`(js--js-qi
|
|
|
|
|
,@(js--optimize-arglist args)))
|
|
|
|
|
|
|
|
|
|
(js< (&rest body) `(js--js-get
|
|
|
|
|
,@(js--optimize-arglist body)))
|
|
|
|
|
(js> (props value)
|
|
|
|
|
`(js--js-funcall
|
|
|
|
|
'(interactor "_putProp")
|
|
|
|
|
,(if (consp props)
|
|
|
|
|
(cons 'list
|
|
|
|
|
(js--optimize-arglist props))
|
|
|
|
|
props)
|
|
|
|
|
,@(js--optimize-arglist (list value))
|
|
|
|
|
))
|
|
|
|
|
(js-handle? (arg) `(js--js-handle-p ,arg)))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
,@forms)
|
|
|
|
|
(js--js-leave-repl))))
|
|
|
|
|
|
|
|
|
|
(defvar js--js-array-as-list nil
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Whether to listify any Array returned by a Mozilla function.
|
|
|
|
|
If nil, the whole Array is treated as a JS symbol.")
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defun js--js-decode-retval (result)
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(pcase (intern (cl-first result))
|
2018-11-05 01:22:15 +01:00
|
|
|
|
('atom (cl-second result))
|
|
|
|
|
('special (intern (cl-second result)))
|
|
|
|
|
('array
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(mapcar #'js--js-decode-retval (cl-second result)))
|
2018-11-05 01:22:15 +01:00
|
|
|
|
('objid
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(or (gethash (cl-second result)
|
|
|
|
|
js--js-references)
|
|
|
|
|
(puthash (cl-second result)
|
|
|
|
|
(make-js--js-handle
|
|
|
|
|
:id (cl-second result)
|
|
|
|
|
:process (inferior-moz-process))
|
|
|
|
|
js--js-references)))
|
|
|
|
|
|
2018-11-05 01:22:15 +01:00
|
|
|
|
('error (signal 'js-js-error (list (cl-second result))))
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(x (error "Unmatched case in js--js-decode-retval: %S" x))))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
2013-05-23 00:37:56 -07:00
|
|
|
|
(defvar comint-last-input-end)
|
|
|
|
|
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(defun js--js-funcall (function &rest arguments)
|
|
|
|
|
"Call the Mozilla function FUNCTION with arguments ARGUMENTS.
|
|
|
|
|
If function is a string, look it up as a property on the global
|
2009-08-15 01:04:14 +00:00
|
|
|
|
object and use the global object for `this'.
|
|
|
|
|
If FUNCTION is a list with one element, use that element as the
|
|
|
|
|
function with the global object for `this', except that if that
|
|
|
|
|
single element is a string, look it up on the global object.
|
|
|
|
|
If FUNCTION is a list with more than one argument, use the list
|
|
|
|
|
up to the last value as a property descriptor and the last
|
|
|
|
|
argument as a function."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(with-js
|
|
|
|
|
(let ((argstr (js--js-encode-value
|
|
|
|
|
(cons function arguments))))
|
|
|
|
|
|
|
|
|
|
(with-current-buffer inferior-moz-buffer
|
|
|
|
|
;; Actual funcall
|
|
|
|
|
(when js--js-array-as-list
|
|
|
|
|
(insert "*"))
|
|
|
|
|
(insert argstr)
|
|
|
|
|
(comint-send-input nil t)
|
|
|
|
|
(js--wait-for-matching-output
|
|
|
|
|
(inferior-moz-process) "EVAL>"
|
|
|
|
|
js-js-timeout)
|
|
|
|
|
(goto-char comint-last-input-end)
|
|
|
|
|
|
|
|
|
|
;; Read the result
|
|
|
|
|
(let* ((json-array-type 'list)
|
|
|
|
|
(result (prog1 (json-read)
|
|
|
|
|
(goto-char (point-max)))))
|
|
|
|
|
(js--js-decode-retval result))))))
|
|
|
|
|
|
|
|
|
|
(defun js--js-new (constructor &rest arguments)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Call CONSTRUCTOR as a constructor, with arguments ARGUMENTS.
|
|
|
|
|
CONSTRUCTOR is a JS handle, a string, or a list of these things."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(apply #'js--js-funcall
|
|
|
|
|
'(interactor "_callNew")
|
|
|
|
|
constructor arguments))
|
|
|
|
|
|
|
|
|
|
(defun js--js-eval (thisobj js)
|
|
|
|
|
(js--js-funcall '(interactor "_callEval") thisobj js))
|
|
|
|
|
|
|
|
|
|
(defun js--js-list (&rest arguments)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Return a Lisp array resulting from evaluating each of ARGUMENTS."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(let ((js--js-array-as-list t))
|
|
|
|
|
(apply #'js--js-funcall '(interactor "_mkArray")
|
|
|
|
|
arguments)))
|
|
|
|
|
|
|
|
|
|
(defun js--js-get (&rest props)
|
|
|
|
|
(apply #'js--js-funcall '(interactor "_getProp") props))
|
|
|
|
|
|
|
|
|
|
(defun js--js-put (props value)
|
|
|
|
|
(js--js-funcall '(interactor "_putProp") props value))
|
|
|
|
|
|
|
|
|
|
(defun js-gc (&optional force)
|
|
|
|
|
"Tell the repl about any objects we don't reference anymore.
|
|
|
|
|
With argument, run even if no intervening GC has happened."
|
|
|
|
|
(interactive)
|
|
|
|
|
|
|
|
|
|
(when force
|
|
|
|
|
(setq js--js-last-gcs-done nil))
|
|
|
|
|
|
|
|
|
|
(let ((this-gcs-done gcs-done) keys num)
|
|
|
|
|
(when (and js--js-references
|
|
|
|
|
(boundp 'inferior-moz-buffer)
|
|
|
|
|
(buffer-live-p inferior-moz-buffer)
|
|
|
|
|
|
|
|
|
|
;; Don't bother running unless we've had an intervening
|
|
|
|
|
;; garbage collection; without a gc, nothing is deleted
|
|
|
|
|
;; from the weak hash table, so it's pointless telling
|
|
|
|
|
;; MozRepl about that references we still hold
|
|
|
|
|
(not (eq js--js-last-gcs-done this-gcs-done))
|
|
|
|
|
|
|
|
|
|
;; Are we looking at a normal prompt? Make sure not to
|
|
|
|
|
;; interrupt the user if he's doing something
|
|
|
|
|
(with-current-buffer inferior-moz-buffer
|
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char (point-max))
|
|
|
|
|
(looking-back js--js-prompt-regexp
|
|
|
|
|
(save-excursion (forward-line 0) (point))))))
|
|
|
|
|
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(setq keys (cl-loop for x being the hash-keys
|
|
|
|
|
of js--js-references
|
|
|
|
|
collect x))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(setq num (js--js-funcall '(repl "_jsGC") (or keys [])))
|
|
|
|
|
|
|
|
|
|
(setq js--js-last-gcs-done this-gcs-done)
|
2009-10-02 03:48:36 +00:00
|
|
|
|
(when (called-interactively-p 'interactive)
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(message "Cleaned %s entries" num))
|
|
|
|
|
|
|
|
|
|
num)))
|
|
|
|
|
|
|
|
|
|
(run-with-idle-timer 30 t #'js-gc)
|
|
|
|
|
|
|
|
|
|
(defun js-eval (js)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Evaluate the JavaScript in JS and return JSON-decoded result."
|
2017-01-29 10:39:55 +02:00
|
|
|
|
(interactive "MJavaScript to evaluate: ")
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(with-js
|
|
|
|
|
(let* ((content-window (js--js-content-window
|
|
|
|
|
(js--get-js-context)))
|
|
|
|
|
(result (js-eval content-window js)))
|
2009-10-02 03:48:36 +00:00
|
|
|
|
(when (called-interactively-p 'interactive)
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(message "%s" (js! "String" result)))
|
|
|
|
|
result)))
|
|
|
|
|
|
|
|
|
|
(defun js--get-tabs ()
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Enumerate all JavaScript contexts available.
|
|
|
|
|
Each context is a list:
|
|
|
|
|
(TITLE URL BROWSER TAB TABBROWSER) for content documents
|
|
|
|
|
(TITLE URL WINDOW) for windows
|
|
|
|
|
|
|
|
|
|
All tabs of a given window are grouped together. The most recent
|
|
|
|
|
window is first. Within each window, the tabs are returned
|
|
|
|
|
left-to-right."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(with-js
|
|
|
|
|
(let (windows)
|
|
|
|
|
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cl-loop with window-mediator = (js! ("Components" "classes"
|
|
|
|
|
"@mozilla.org/appshell/window-mediator;1"
|
|
|
|
|
"getService")
|
|
|
|
|
(js< "Components" "interfaces"
|
|
|
|
|
"nsIWindowMediator"))
|
|
|
|
|
with enumerator = (js! (window-mediator "getEnumerator") nil)
|
|
|
|
|
|
|
|
|
|
while (js? (js! (enumerator "hasMoreElements")))
|
|
|
|
|
for window = (js! (enumerator "getNext"))
|
|
|
|
|
for window-info = (js-list window
|
|
|
|
|
(js< window "document" "title")
|
|
|
|
|
(js! (window "location" "toString"))
|
|
|
|
|
(js< window "closed")
|
|
|
|
|
(js< window "windowState"))
|
|
|
|
|
|
|
|
|
|
unless (or (js? (cl-fourth window-info))
|
|
|
|
|
(eq (cl-fifth window-info) 2))
|
|
|
|
|
do (push window-info windows))
|
|
|
|
|
|
2017-01-25 21:34:46 -05:00
|
|
|
|
(cl-loop for (window title location) in windows
|
|
|
|
|
collect (list title location window)
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
|
|
|
|
|
for gbrowser = (js< window "gBrowser")
|
|
|
|
|
if (js-handle? gbrowser)
|
|
|
|
|
nconc (cl-loop
|
|
|
|
|
for x below (js< gbrowser "browsers" "length")
|
|
|
|
|
collect (js-list (js< gbrowser
|
|
|
|
|
"browsers"
|
|
|
|
|
x
|
|
|
|
|
"contentDocument"
|
|
|
|
|
"title")
|
|
|
|
|
|
|
|
|
|
(js! (gbrowser
|
|
|
|
|
"browsers"
|
|
|
|
|
x
|
|
|
|
|
"contentWindow"
|
|
|
|
|
"location"
|
|
|
|
|
"toString"))
|
|
|
|
|
(js< gbrowser
|
|
|
|
|
"browsers"
|
|
|
|
|
x)
|
|
|
|
|
|
|
|
|
|
(js! (gbrowser
|
|
|
|
|
"tabContainer"
|
|
|
|
|
"childNodes"
|
|
|
|
|
"item")
|
|
|
|
|
x)
|
|
|
|
|
|
|
|
|
|
gbrowser))))))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defvar js-read-tab-history nil)
|
|
|
|
|
|
2013-05-23 00:37:56 -07:00
|
|
|
|
(declare-function ido-chop "ido" (items elem))
|
|
|
|
|
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(defun js--read-tab (prompt)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Read a Mozilla tab with prompt PROMPT.
|
2015-11-17 15:28:50 -08:00
|
|
|
|
Return a cons of (TYPE . OBJECT). TYPE is either `window' or
|
|
|
|
|
`tab', and OBJECT is a JavaScript handle to a ChromeWindow or a
|
2009-08-15 01:04:14 +00:00
|
|
|
|
browser, respectively."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
;; Prime IDO
|
|
|
|
|
(unless ido-mode
|
2011-04-22 20:44:26 +02:00
|
|
|
|
(ido-mode 1)
|
|
|
|
|
(ido-mode -1))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(with-js
|
2012-04-26 08:43:28 -04:00
|
|
|
|
(let ((tabs (js--get-tabs)) selected-tab-cname
|
|
|
|
|
selected-tab prev-hitab)
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
;; Disambiguate names
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(setq tabs
|
|
|
|
|
(cl-loop with tab-names = (make-hash-table :test 'equal)
|
|
|
|
|
for tab in tabs
|
|
|
|
|
for cname = (format "%s (%s)"
|
|
|
|
|
(cl-second tab) (cl-first tab))
|
|
|
|
|
for num = (cl-incf (gethash cname tab-names -1))
|
|
|
|
|
if (> num 0)
|
|
|
|
|
do (setq cname (format "%s <%d>" cname num))
|
|
|
|
|
collect (cons cname tab)))
|
|
|
|
|
|
|
|
|
|
(cl-labels
|
|
|
|
|
((find-tab-by-cname
|
|
|
|
|
(cname)
|
|
|
|
|
(cl-loop for tab in tabs
|
|
|
|
|
if (equal (car tab) cname)
|
|
|
|
|
return (cdr tab)))
|
|
|
|
|
|
|
|
|
|
(mogrify-highlighting
|
|
|
|
|
(hitab unhitab)
|
|
|
|
|
|
|
|
|
|
;; Hack to reduce the number of
|
|
|
|
|
;; round-trips to mozilla
|
|
|
|
|
(let (cmds)
|
|
|
|
|
(cond
|
|
|
|
|
;; Highlighting tab
|
|
|
|
|
((cl-fourth hitab)
|
|
|
|
|
(push '(js! ((cl-fourth hitab) "setAttribute")
|
|
|
|
|
"style"
|
|
|
|
|
"color: red; font-weight: bold")
|
|
|
|
|
cmds)
|
|
|
|
|
|
|
|
|
|
;; Highlight window proper
|
|
|
|
|
(push '(js! ((cl-third hitab)
|
|
|
|
|
"setAttribute")
|
|
|
|
|
"style"
|
|
|
|
|
"border: 8px solid red")
|
|
|
|
|
cmds)
|
|
|
|
|
|
|
|
|
|
;; Select tab, when appropriate
|
|
|
|
|
(when js-js-switch-tabs
|
|
|
|
|
(push
|
|
|
|
|
'(js> ((cl-fifth hitab) "selectedTab") (cl-fourth hitab))
|
|
|
|
|
cmds)))
|
|
|
|
|
|
|
|
|
|
;; Highlighting whole window
|
|
|
|
|
((cl-third hitab)
|
|
|
|
|
(push '(js! ((cl-third hitab) "document"
|
|
|
|
|
"documentElement" "setAttribute")
|
|
|
|
|
"style"
|
|
|
|
|
(concat "-moz-appearance: none;"
|
|
|
|
|
"border: 8px solid red;"))
|
|
|
|
|
cmds)))
|
|
|
|
|
|
|
|
|
|
(cond
|
|
|
|
|
;; Unhighlighting tab
|
|
|
|
|
((cl-fourth unhitab)
|
|
|
|
|
(push '(js! ((cl-fourth unhitab) "setAttribute") "style" "")
|
|
|
|
|
cmds)
|
|
|
|
|
(push '(js! ((cl-third unhitab) "setAttribute") "style" "")
|
|
|
|
|
cmds))
|
|
|
|
|
|
|
|
|
|
;; Unhighlighting window
|
|
|
|
|
((cl-third unhitab)
|
|
|
|
|
(push '(js! ((cl-third unhitab) "document"
|
|
|
|
|
"documentElement" "setAttribute")
|
|
|
|
|
"style" "")
|
|
|
|
|
cmds)))
|
|
|
|
|
|
|
|
|
|
(eval (list 'with-js
|
|
|
|
|
(cons 'js-list (nreverse cmds))))))
|
|
|
|
|
|
|
|
|
|
(command-hook
|
|
|
|
|
()
|
|
|
|
|
(let* ((tab (find-tab-by-cname (car ido-matches))))
|
|
|
|
|
(mogrify-highlighting tab prev-hitab)
|
|
|
|
|
(setq prev-hitab tab)))
|
|
|
|
|
|
|
|
|
|
(setup-hook
|
|
|
|
|
()
|
|
|
|
|
;; Fiddle with the match list a bit: if our first match
|
|
|
|
|
;; is a tabbrowser window, rotate the match list until
|
|
|
|
|
;; the active tab comes up
|
|
|
|
|
(let ((matched-tab (find-tab-by-cname (car ido-matches))))
|
|
|
|
|
(when (and matched-tab
|
|
|
|
|
(null (cl-fourth matched-tab))
|
|
|
|
|
(equal "navigator:browser"
|
|
|
|
|
(js! ((cl-third matched-tab)
|
|
|
|
|
"document"
|
|
|
|
|
"documentElement"
|
|
|
|
|
"getAttribute")
|
|
|
|
|
"windowtype")))
|
|
|
|
|
|
|
|
|
|
(cl-loop with tab-to-match = (js< (cl-third matched-tab)
|
|
|
|
|
"gBrowser"
|
|
|
|
|
"selectedTab")
|
|
|
|
|
|
|
|
|
|
for match in ido-matches
|
|
|
|
|
for candidate-tab = (find-tab-by-cname match)
|
|
|
|
|
if (eq (cl-fourth candidate-tab) tab-to-match)
|
|
|
|
|
do (setq ido-cur-list
|
|
|
|
|
(ido-chop ido-cur-list match))
|
|
|
|
|
and return t)))
|
|
|
|
|
|
|
|
|
|
(add-hook 'post-command-hook #'command-hook t t)))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(unwind-protect
|
2016-05-04 08:53:00 -04:00
|
|
|
|
;; FIXME: Don't impose IDO on the user.
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(setq selected-tab-cname
|
|
|
|
|
(let ((ido-minibuffer-setup-hook
|
|
|
|
|
(cons #'setup-hook ido-minibuffer-setup-hook)))
|
|
|
|
|
(ido-completing-read
|
|
|
|
|
prompt
|
|
|
|
|
(mapcar #'car tabs)
|
|
|
|
|
nil t nil
|
|
|
|
|
'js-read-tab-history)))
|
|
|
|
|
|
|
|
|
|
(when prev-hitab
|
|
|
|
|
(mogrify-highlighting nil prev-hitab)
|
|
|
|
|
(setq prev-hitab nil)))
|
|
|
|
|
|
|
|
|
|
(add-to-history 'js-read-tab-history selected-tab-cname)
|
|
|
|
|
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(setq selected-tab (cl-loop for tab in tabs
|
|
|
|
|
if (equal (car tab) selected-tab-cname)
|
|
|
|
|
return (cdr tab)))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cons (if (cl-fourth selected-tab) 'browser 'window)
|
|
|
|
|
(cl-third selected-tab))))))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defun js--guess-eval-defun-info (pstate)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Helper function for `js-eval-defun'.
|
|
|
|
|
Return a list (NAME . CLASSPARTS), where CLASSPARTS is a list of
|
|
|
|
|
strings making up the class name and NAME is the name of the
|
|
|
|
|
function part."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(cond ((and (= (length pstate) 3)
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(eq (js--pitem-type (cl-first pstate)) 'function)
|
|
|
|
|
(= (length (js--pitem-name (cl-first pstate))) 1)
|
|
|
|
|
(consp (js--pitem-type (cl-second pstate))))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(append (js--pitem-name (cl-second pstate))
|
|
|
|
|
(list (cl-first (js--pitem-name (cl-first pstate))))))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
((and (= (length pstate) 2)
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(eq (js--pitem-type (cl-first pstate)) 'function))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(append
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(butlast (js--pitem-name (cl-first pstate)))
|
|
|
|
|
(list (car (last (js--pitem-name (cl-first pstate)))))))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(t (error "Function not a toplevel defun or class member"))))
|
|
|
|
|
|
|
|
|
|
(defvar js--js-context nil
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"The current JavaScript context.
|
|
|
|
|
This is a cons like the one returned from `js--read-tab'.
|
|
|
|
|
Change with `js-set-js-context'.")
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defconst js--js-inserter
|
|
|
|
|
"(function(func_info,func) {
|
|
|
|
|
func_info.unshift('window');
|
|
|
|
|
var obj = window;
|
|
|
|
|
for(var i = 1; i < func_info.length - 1; ++i) {
|
|
|
|
|
var next = obj[func_info[i]];
|
|
|
|
|
if(typeof next !== 'object' && typeof next !== 'function') {
|
|
|
|
|
next = obj.prototype && obj.prototype[func_info[i]];
|
|
|
|
|
if(typeof next !== 'object' && typeof next !== 'function') {
|
|
|
|
|
alert('Could not find ' + func_info.slice(0, i+1).join('.') +
|
|
|
|
|
' or ' + func_info.slice(0, i+1).join('.') + '.prototype');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func_info.splice(i+1, 0, 'prototype');
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
obj[func_info[i]] = func;
|
|
|
|
|
alert('Successfully updated '+func_info.join('.'));
|
|
|
|
|
})")
|
|
|
|
|
|
|
|
|
|
(defun js-set-js-context (context)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Set the JavaScript context to CONTEXT.
|
|
|
|
|
When called interactively, prompt for CONTEXT."
|
2017-01-29 10:39:55 +02:00
|
|
|
|
(interactive (list (js--read-tab "JavaScript Context: ")))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(setq js--js-context context))
|
|
|
|
|
|
|
|
|
|
(defun js--get-js-context ()
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Return a valid JavaScript context.
|
|
|
|
|
If one hasn't been set, or if it's stale, prompt for a new one."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(with-js
|
|
|
|
|
(when (or (null js--js-context)
|
|
|
|
|
(js--js-handle-expired-p (cdr js--js-context))
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(pcase (car js--js-context)
|
2018-11-05 01:22:15 +01:00
|
|
|
|
('window (js? (js< (cdr js--js-context) "closed")))
|
|
|
|
|
('browser (not (js? (js< (cdr js--js-context)
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
"contentDocument"))))
|
|
|
|
|
(x (error "Unmatched case in js--get-js-context: %S" x))))
|
2017-01-29 10:39:55 +02:00
|
|
|
|
(setq js--js-context (js--read-tab "JavaScript Context: ")))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
js--js-context))
|
|
|
|
|
|
|
|
|
|
(defun js--js-content-window (context)
|
|
|
|
|
(with-js
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(pcase (car context)
|
2018-11-05 01:22:15 +01:00
|
|
|
|
('window (cdr context))
|
|
|
|
|
('browser (js< (cdr context)
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
"contentWindow" "wrappedJSObject"))
|
|
|
|
|
(x (error "Unmatched case in js--js-content-window: %S" x)))))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(defun js--make-nsilocalfile (path)
|
|
|
|
|
(with-js
|
|
|
|
|
(let ((file (js-create-instance "@mozilla.org/file/local;1"
|
|
|
|
|
"nsILocalFile")))
|
|
|
|
|
(js! (file "initWithPath") path)
|
|
|
|
|
file)))
|
|
|
|
|
|
|
|
|
|
(defun js--js-add-resource-alias (alias path)
|
|
|
|
|
(with-js
|
|
|
|
|
(let* ((io-service (js-get-service "@mozilla.org/network/io-service;1"
|
|
|
|
|
"nsIIOService"))
|
|
|
|
|
(res-prot (js! (io-service "getProtocolHandler") "resource"))
|
|
|
|
|
(res-prot (js-qi res-prot "nsIResProtocolHandler"))
|
|
|
|
|
(path-file (js--make-nsilocalfile path))
|
|
|
|
|
(path-uri (js! (io-service "newFileURI") path-file)))
|
|
|
|
|
(js! (res-prot "setSubstitution") alias path-uri))))
|
|
|
|
|
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cl-defun js-eval-defun ()
|
2009-08-15 01:04:14 +00:00
|
|
|
|
"Update a Mozilla tab using the JavaScript defun at point."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(interactive)
|
|
|
|
|
|
|
|
|
|
;; This function works by generating a temporary file that contains
|
|
|
|
|
;; the function we'd like to insert. We then use the elisp-js bridge
|
|
|
|
|
;; to command mozilla to load this file by inserting a script tag
|
|
|
|
|
;; into the document we set. This way, debuggers and such will have
|
|
|
|
|
;; a way to find the source of the just-inserted function.
|
|
|
|
|
;;
|
|
|
|
|
;; We delete the temporary file if there's an error, but otherwise
|
|
|
|
|
;; we add an unload event listener on the Mozilla side to delete the
|
|
|
|
|
;; file.
|
|
|
|
|
|
|
|
|
|
(save-excursion
|
|
|
|
|
(let (begin end pstate defun-info temp-name defun-body)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
(js-end-of-defun)
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(setq end (point))
|
|
|
|
|
(js--ensure-cache)
|
2009-08-15 01:04:14 +00:00
|
|
|
|
(js-beginning-of-defun)
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(re-search-forward "\\_<function\\_>")
|
|
|
|
|
(setq begin (match-beginning 0))
|
|
|
|
|
(setq pstate (js--forward-pstate))
|
|
|
|
|
|
|
|
|
|
(when (or (null pstate)
|
|
|
|
|
(> (point) end))
|
|
|
|
|
(error "Could not locate function definition"))
|
|
|
|
|
|
|
|
|
|
(setq defun-info (js--guess-eval-defun-info pstate))
|
|
|
|
|
|
|
|
|
|
(let ((overlay (make-overlay begin end)))
|
|
|
|
|
(overlay-put overlay 'face 'highlight)
|
|
|
|
|
(unwind-protect
|
|
|
|
|
(unless (y-or-n-p (format "Send %s to Mozilla? "
|
|
|
|
|
(mapconcat #'identity defun-info ".")))
|
|
|
|
|
(message "") ; question message lingers until next command
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(cl-return-from js-eval-defun))
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(delete-overlay overlay)))
|
|
|
|
|
|
|
|
|
|
(setq defun-body (buffer-substring-no-properties begin end))
|
|
|
|
|
|
|
|
|
|
(make-directory js-js-tmpdir t)
|
|
|
|
|
|
|
|
|
|
;; (Re)register a Mozilla resource URL to point to the
|
|
|
|
|
;; temporary directory
|
|
|
|
|
(js--js-add-resource-alias "js" js-js-tmpdir)
|
|
|
|
|
|
|
|
|
|
(setq temp-name (make-temp-file (concat js-js-tmpdir
|
|
|
|
|
"/js-")
|
|
|
|
|
nil ".js"))
|
|
|
|
|
(unwind-protect
|
|
|
|
|
(with-js
|
|
|
|
|
(with-temp-buffer
|
|
|
|
|
(insert js--js-inserter)
|
|
|
|
|
(insert "(")
|
|
|
|
|
(insert (json-encode-list defun-info))
|
|
|
|
|
(insert ",\n")
|
|
|
|
|
(insert defun-body)
|
|
|
|
|
(insert "\n)")
|
|
|
|
|
(write-region (point-min) (point-max) temp-name
|
|
|
|
|
nil 1))
|
|
|
|
|
|
|
|
|
|
;; Give Mozilla responsibility for deleting this file
|
|
|
|
|
(let* ((content-window (js--js-content-window
|
|
|
|
|
(js--get-js-context)))
|
|
|
|
|
(content-document (js< content-window "document"))
|
|
|
|
|
(head (if (js? (js< content-document "body"))
|
|
|
|
|
;; Regular content
|
|
|
|
|
(js< (js! (content-document "getElementsByTagName")
|
|
|
|
|
"head")
|
|
|
|
|
0)
|
|
|
|
|
;; Chrome
|
|
|
|
|
(js< content-document "documentElement")))
|
|
|
|
|
(elem (js! (content-document "createElementNS")
|
|
|
|
|
"http://www.w3.org/1999/xhtml" "script")))
|
|
|
|
|
|
|
|
|
|
(js! (elem "setAttribute") "type" "text/javascript")
|
|
|
|
|
(js! (elem "setAttribute") "src"
|
|
|
|
|
(format "resource://js/%s"
|
|
|
|
|
(file-name-nondirectory temp-name)))
|
|
|
|
|
|
|
|
|
|
(js! (head "appendChild") elem)
|
|
|
|
|
|
|
|
|
|
(js! (content-window "addEventListener") "unload"
|
|
|
|
|
(js! ((js-new
|
|
|
|
|
"Function" "file"
|
|
|
|
|
"return function() { file.remove(false) }"))
|
|
|
|
|
(js--make-nsilocalfile temp-name))
|
|
|
|
|
'false)
|
|
|
|
|
(setq temp-name nil)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
;; temp-name is set to nil on success
|
|
|
|
|
(when temp-name
|
|
|
|
|
(delete-file temp-name))))))
|
|
|
|
|
|
2019-03-23 20:14:29 -07:00
|
|
|
|
;;; Syntax extensions
|
|
|
|
|
|
|
|
|
|
(defvar js-syntactic-mode-name t
|
|
|
|
|
"If non-nil, print enabled syntaxes in the mode name.")
|
|
|
|
|
|
|
|
|
|
(defun js--update-mode-name ()
|
|
|
|
|
"Print enabled syntaxes if `js-syntactic-mode-name' is t."
|
|
|
|
|
(when js-syntactic-mode-name
|
|
|
|
|
(setq mode-name (concat "JavaScript"
|
|
|
|
|
(if js-jsx-syntax "+JSX" "")))))
|
|
|
|
|
|
|
|
|
|
(defun js--idly-update-mode-name ()
|
|
|
|
|
"Update `mode-name' whenever Emacs goes idle.
|
|
|
|
|
In case `js-jsx-syntax' is updated, especially by features of
|
|
|
|
|
Emacs like .dir-locals.el or file variables, this ensures the
|
|
|
|
|
modeline eventually reflects which syntaxes are enabled."
|
|
|
|
|
(let (timer)
|
|
|
|
|
(setq timer
|
|
|
|
|
(run-with-idle-timer
|
|
|
|
|
0 t
|
|
|
|
|
(lambda (buffer)
|
|
|
|
|
(if (buffer-live-p buffer)
|
|
|
|
|
(with-current-buffer buffer
|
|
|
|
|
(js--update-mode-name))
|
|
|
|
|
(cancel-timer timer)))
|
|
|
|
|
(current-buffer)))))
|
|
|
|
|
|
|
|
|
|
(defun js-jsx-enable ()
|
|
|
|
|
"Enable JSX in the current buffer."
|
|
|
|
|
(interactive)
|
|
|
|
|
(setq-local js-jsx-syntax t)
|
|
|
|
|
(js--update-mode-name))
|
|
|
|
|
|
|
|
|
|
(defvar js-jsx-regexps
|
|
|
|
|
(list "\\_<\\(?:var\\|let\\|const\\|import\\)\\_>.*?React")
|
|
|
|
|
"Regexps for detecting JSX in JavaScript buffers.
|
|
|
|
|
When `js-jsx-detect-syntax' is non-nil and any of these regexps
|
|
|
|
|
match text near the beginning of a JavaScript buffer,
|
|
|
|
|
`js-jsx-syntax' (which see) will be made buffer-local and set to
|
|
|
|
|
t.")
|
|
|
|
|
|
|
|
|
|
(defun js-jsx--detect-and-enable (&optional arbitrarily)
|
|
|
|
|
"Detect if JSX is likely to be used, and enable it if so.
|
|
|
|
|
Might make `js-jsx-syntax' buffer-local and set it to t. Matches
|
|
|
|
|
from the beginning of the buffer, unless optional arg ARBITRARILY
|
|
|
|
|
is non-nil. Return t after enabling, nil otherwise."
|
|
|
|
|
(when (or (and (buffer-file-name)
|
|
|
|
|
(string-match-p "\\.jsx\\'" (buffer-file-name)))
|
|
|
|
|
(and js-jsx-detect-syntax
|
|
|
|
|
(save-excursion
|
|
|
|
|
(unless arbitrarily
|
|
|
|
|
(goto-char (point-min)))
|
|
|
|
|
(catch 'match
|
|
|
|
|
(mapc
|
|
|
|
|
(lambda (regexp)
|
|
|
|
|
(if (re-search-forward regexp 4000 t) (throw 'match t)))
|
|
|
|
|
js-jsx-regexps)
|
|
|
|
|
nil))))
|
|
|
|
|
(js-jsx-enable)
|
|
|
|
|
t))
|
|
|
|
|
|
|
|
|
|
(defun js-jsx--detect-after-change (beg end _len)
|
|
|
|
|
"Detect if JSX is likely to be used after a change.
|
|
|
|
|
This function is intended for use in `after-change-functions'."
|
|
|
|
|
(when (<= end 4000)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char beg)
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(save-restriction
|
|
|
|
|
(narrow-to-region (point) end)
|
|
|
|
|
(when (js-jsx--detect-and-enable 'arbitrarily)
|
|
|
|
|
(remove-hook 'after-change-functions #'js-jsx--detect-after-change t))))))
|
|
|
|
|
|
2009-08-14 23:02:38 +00:00
|
|
|
|
;;; Main Function
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
2015-07-19 08:18:56 +03:00
|
|
|
|
(define-derived-mode js-mode prog-mode "JavaScript"
|
Derive from prog-mode, use derived-mode-p, and fix up various
minor style issues in lisp/progmodes.
* lisp/progmodes/vhdl-mode.el (vhdl-write-file-hooks-init)
(vhdl-hs-minor-mode, vhdl-ps-print-init): Fix make-local-variable ->
make-local-hook.
* lisp/progmodes/sh-script.el (sh-require-final-newline): Remove.
(sh-set-shell): Don't set require-final-newline since it's already done
by prog-mode.
* lisp/progmodes/modula2.el (m2-mode): Don't make m2-end-comment-column
since we never set it.
* lisp/progmodes/ebrowse.el (ebrowse-set-tree-indentation):
Use read-string and standard prompt.
* lisp/progmodes/dcl-mode.el (dcl-mode-map): Move init into declaration.
* lisp/progmodes/meta-mode.el (meta-mode-abbrev-table): Merge init and decl.
(meta-common-mode-syntax-table): Rename from meta-mode-syntax-table.
(meta-common-mode-map): Rename from meta-mode-map.
Remove C-m binding, which is a user preference, not mode specific.
(meta-common-mode): New major mode; replace meta-common-initialization.
* lisp/progmodes/js.el (js-mode): Call syntax-propertize rather than messing
around with font-lock.
* lisp/progmodes/etags.el (select-tags-table-mode):
Derive from special-mode.
* lisp/progmodes/octave-mod.el (octave-mode):
* lisp/progmodes/gdb-mi.el (gdb-inferior-io-mode, gdb-threads-mode)
(gdb-memory-mode, gdb-disassembly-mode, gdb-breakpoints-mode)
(gdb-frames-mode, gdb-locals-mode, gdb-registers-mode):
Let define-derived-mode do its job.
* lisp/progmodes/cpp.el (cpp-edit-mode-map):
Move initialization into declaration.
(cpp-edit-mode): Use define-derived-mode.
(cpp-edit-load): Use derived-mode-p.
* lisp/progmodes/mixal-mode.el (mixal-mode):
* lisp/progmodes/f90.el (f90-mode):
* lisp/progmodes/cfengine.el (cfengine-mode): Don't bother setting
require-final-newline since prog-mode does it already.
* lisp/progmodes/cc-cmds.el (c-update-modeline): Use match-string.
* lisp/progmodes/asm-mode.el (asm-mode-map): Fix menu setup.
* lisp/progmodes/antlr-mode.el: Require cc-mode upfront.
(antlr-mode-syntax-table, antlr-action-syntax-table): Initialize in
the declaration.
(antlr-directory-dependencies, antlr-show-makefile-rules):
Use derived-mode-p.
(antlr-language-option): Don't assume point-min==1.
(antlr-mode): Use define-derived-mode.
* lisp/progmodes/ada-mode.el: Use derived-mode-p.
(ada-mode): Use define-derived-mode.
Use hack-local-variables-hook.
* lisp/progmodes/vhdl-mode.el (vhdl-mode):
* lisp/progmodes/verilog-mode.el (verilog-mode):
* lisp/progmodes/vera-mode.el (vera-mode):
* lisp/progmodes/sql.el (sql-mode):
* lisp/progmodes/scheme.el (scheme-mode):
* lisp/progmodes/perl-mode.el (perl-mode):
* lisp/progmodes/octave-inf.el (inferior-octave-mode):
* lisp/progmodes/autoconf.el (autoconf-mode):
* lisp/progmodes/m4-mode.el (m4-mode):
* lisp/progmodes/inf-lisp.el (inferior-lisp-mode):
* lisp/progmodes/idlwave.el (idlwave-mode):
* lisp/progmodes/icon.el (icon-mode):
* lisp/progmodes/idlw-help.el (idlwave-help-mode):
* lisp/progmodes/dcl-mode.el (dcl-mode):
* lisp/progmodes/idlw-shell.el (idlwave-shell-mode):
* lisp/progmodes/ebrowse.el (ebrowse-tree-mode, ebrowse-electric-list-mode)
(ebrowse-member-mode, ebrowse-electric-position-mode):
Use define-derived-mode.
* lisp/progmodes/xscheme.el (xscheme-start)
(local-set-scheme-interaction-buffer, scheme-interaction-mode):
* lisp/progmodes/which-func.el (which-function):
* lisp/progmodes/vhdl-mode.el (vhdl-set-style):
* lisp/progmodes/verilog-mode.el (verilog-set-compile-command)
(verilog-modify-compile-command, verilog-error-regexp-add-xemacs)
(verilog-set-define, verilog-auto-reeval-locals):
* lisp/progmodes/sql.el (sql-product-font-lock, sql-interactive-mode):
* lisp/progmodes/simula.el (simula-mode):
* lisp/progmodes/scheme.el (scheme-mode-variables, dsssl-mode):
* lisp/progmodes/python.el (python-check, python-mode):
* lisp/progmodes/prolog.el (prolog-mode-variables):
* lisp/progmodes/gud.el (gud-tooltip-activate-mouse-motions):
* lisp/progmodes/ebrowse.el (ebrowse-view-file-other-frame):
* lisp/progmodes/delphi.el (delphi-mode):
* lisp/progmodes/cc-styles.el (c-setup-paragraph-variables):
* lisp/progmodes/cc-mode.el (c-basic-common-init, c-common-init)
(c-font-lock-init): Move make-local-variable to their setq.
* lisp/progmodes/xscheme.el (exit-scheme-interaction-mode)
(xscheme-enter-interaction-mode, xscheme-enter-debugger-mode)
(xscheme-debugger-mode-p, xscheme-send-string-1):
* lisp/progmodes/tcl.el (inferior-tcl-proc, tcl-current-word)
(tcl-load-file, tcl-restart-with-file):
* lisp/progmodes/ps-mode.el (ps-run-running):
* lisp/progmodes/gdb-mi.el (gud-watch, gdb-mouse-set-clear-breakpoint):
* lisp/progmodes/js.el (js--get-all-known-symbols):
* lisp/progmodes/inf-lisp.el (inferior-lisp-proc):
* lisp/progmodes/idlwave.el (idlwave-beginning-of-statement)
(idlwave-template, idlwave-update-buffer-routine-info)
(idlwave-update-current-buffer-info)
(idlwave-get-routine-info-from-buffers, idlwave-choose)
(idlwave-scan-class-info, idlwave-fix-keywords)
(idlwave-list-buffer-load-path-shadows):
* lisp/progmodes/idlw-toolbar.el (idlwave-toolbar, idlwave-toolbar-add)
(idlwave-toolbar-remove):
* lisp/progmodes/idlw-shell.el (idlwave-shell-save-and-action)
(idlwave-shell-file-name, idlwave-shell-electric-debug-all-off)
(idlwave-shell-menu-def):
* lisp/progmodes/idlw-complete-structtag.el
(idlwave-prepare-structure-tag-completion):
* lisp/progmodes/gud.el (gud-set-buffer):
* lisp/progmodes/f90.el (f90-backslash-not-special):
* lisp/progmodes/delphi.el (delphi-find-unit): Use derived-mode-p.
2010-12-10 15:00:25 -05:00
|
|
|
|
"Major mode for editing JavaScript."
|
2009-08-14 23:02:38 +00:00
|
|
|
|
:group 'js
|
2016-05-04 08:53:00 -04:00
|
|
|
|
(setq-local indent-line-function #'js-indent-line)
|
|
|
|
|
(setq-local beginning-of-defun-function #'js-beginning-of-defun)
|
|
|
|
|
(setq-local end-of-defun-function #'js-end-of-defun)
|
Convert several major modes to setq-local.
* emacs-lisp/lisp-mode.el (lisp-mode-variables, lisp-mode):
* progmodes/autoconf.el (autoconf-mode):
* progmodes/js.el (js-mode):
* progmodes/make-mode.el (makefile-mode, makefile-makepp-mode)
(makefile-bsdmake-mode, makefile-imake-mode, makefile-browse):
* progmodes/perl-mode.el (perl-mode):
* progmodes/sh-script.el (sh-mode, sh-set-shell):
* textmodes/css-mode.el (css-mode):
* textmodes/sgml-mode.el (html-mode, sgml-mode)
(sgml-tags-invisible, sgml-guess-indent):
* textmodes/tex-mode.el (tex-common-initialization)
(latex-complete-bibtex-keys, tex-shell, tex-main-file)
(doctex-mode, plain-tex-mode, latex-mode):
* textmodes/texinfo.el (texinfo-mode): Use setq-local.
2012-12-01 12:09:55 +08:00
|
|
|
|
(setq-local open-paren-in-column-0-is-defun-start nil)
|
2017-02-25 10:27:48 -07:00
|
|
|
|
(setq-local font-lock-defaults
|
|
|
|
|
(list js--font-lock-keywords nil nil nil nil
|
|
|
|
|
'(font-lock-syntactic-face-function
|
|
|
|
|
. js-font-lock-syntactic-face-function)))
|
Convert several major modes to setq-local.
* emacs-lisp/lisp-mode.el (lisp-mode-variables, lisp-mode):
* progmodes/autoconf.el (autoconf-mode):
* progmodes/js.el (js-mode):
* progmodes/make-mode.el (makefile-mode, makefile-makepp-mode)
(makefile-bsdmake-mode, makefile-imake-mode, makefile-browse):
* progmodes/perl-mode.el (perl-mode):
* progmodes/sh-script.el (sh-mode, sh-set-shell):
* textmodes/css-mode.el (css-mode):
* textmodes/sgml-mode.el (html-mode, sgml-mode)
(sgml-tags-invisible, sgml-guess-indent):
* textmodes/tex-mode.el (tex-common-initialization)
(latex-complete-bibtex-keys, tex-shell, tex-main-file)
(doctex-mode, plain-tex-mode, latex-mode):
* textmodes/texinfo.el (texinfo-mode): Use setq-local.
2012-12-01 12:09:55 +08:00
|
|
|
|
(setq-local syntax-propertize-function #'js-syntax-propertize)
|
2019-03-08 16:29:02 -08:00
|
|
|
|
(add-hook 'syntax-propertize-extend-region-functions
|
|
|
|
|
#'syntax-propertize-multiline 'append 'local)
|
2019-02-17 21:16:13 -08:00
|
|
|
|
(add-hook 'syntax-propertize-extend-region-functions
|
|
|
|
|
#'js--syntax-propertize-extend-region 'append 'local)
|
2015-09-27 10:04:09 +02:00
|
|
|
|
(setq-local prettify-symbols-alist js--prettify-symbols-alist)
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
Convert several major modes to setq-local.
* emacs-lisp/lisp-mode.el (lisp-mode-variables, lisp-mode):
* progmodes/autoconf.el (autoconf-mode):
* progmodes/js.el (js-mode):
* progmodes/make-mode.el (makefile-mode, makefile-makepp-mode)
(makefile-bsdmake-mode, makefile-imake-mode, makefile-browse):
* progmodes/perl-mode.el (perl-mode):
* progmodes/sh-script.el (sh-mode, sh-set-shell):
* textmodes/css-mode.el (css-mode):
* textmodes/sgml-mode.el (html-mode, sgml-mode)
(sgml-tags-invisible, sgml-guess-indent):
* textmodes/tex-mode.el (tex-common-initialization)
(latex-complete-bibtex-keys, tex-shell, tex-main-file)
(doctex-mode, plain-tex-mode, latex-mode):
* textmodes/texinfo.el (texinfo-mode): Use setq-local.
2012-12-01 12:09:55 +08:00
|
|
|
|
(setq-local parse-sexp-ignore-comments t)
|
|
|
|
|
(setq-local which-func-imenu-joiner-function #'js--which-func-joiner)
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
;; Comments
|
Convert several major modes to setq-local.
* emacs-lisp/lisp-mode.el (lisp-mode-variables, lisp-mode):
* progmodes/autoconf.el (autoconf-mode):
* progmodes/js.el (js-mode):
* progmodes/make-mode.el (makefile-mode, makefile-makepp-mode)
(makefile-bsdmake-mode, makefile-imake-mode, makefile-browse):
* progmodes/perl-mode.el (perl-mode):
* progmodes/sh-script.el (sh-mode, sh-set-shell):
* textmodes/css-mode.el (css-mode):
* textmodes/sgml-mode.el (html-mode, sgml-mode)
(sgml-tags-invisible, sgml-guess-indent):
* textmodes/tex-mode.el (tex-common-initialization)
(latex-complete-bibtex-keys, tex-shell, tex-main-file)
(doctex-mode, plain-tex-mode, latex-mode):
* textmodes/texinfo.el (texinfo-mode): Use setq-local.
2012-12-01 12:09:55 +08:00
|
|
|
|
(setq-local comment-start "// ")
|
|
|
|
|
(setq-local comment-end "")
|
2018-09-14 10:23:39 -04:00
|
|
|
|
(setq-local fill-paragraph-function #'js-fill-paragraph)
|
2017-08-27 12:54:01 -06:00
|
|
|
|
(setq-local normal-auto-fill-function #'js-do-auto-fill)
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
;; Parse cache
|
|
|
|
|
(add-hook 'before-change-functions #'js--flush-caches t t)
|
|
|
|
|
|
|
|
|
|
;; Frameworks
|
|
|
|
|
(js--update-quick-match-re)
|
|
|
|
|
|
2019-03-23 20:14:29 -07:00
|
|
|
|
;; Syntax extensions
|
|
|
|
|
(unless (js-jsx--detect-and-enable)
|
|
|
|
|
(add-hook 'after-change-functions #'js-jsx--detect-after-change nil t))
|
|
|
|
|
(js--update-mode-name) ; If `js-jsx-syntax' was set from outside.
|
|
|
|
|
(js--idly-update-mode-name)
|
|
|
|
|
|
2009-08-14 23:02:38 +00:00
|
|
|
|
;; Imenu
|
|
|
|
|
(setq imenu-case-fold-search nil)
|
Convert several major modes to setq-local.
* emacs-lisp/lisp-mode.el (lisp-mode-variables, lisp-mode):
* progmodes/autoconf.el (autoconf-mode):
* progmodes/js.el (js-mode):
* progmodes/make-mode.el (makefile-mode, makefile-makepp-mode)
(makefile-bsdmake-mode, makefile-imake-mode, makefile-browse):
* progmodes/perl-mode.el (perl-mode):
* progmodes/sh-script.el (sh-mode, sh-set-shell):
* textmodes/css-mode.el (css-mode):
* textmodes/sgml-mode.el (html-mode, sgml-mode)
(sgml-tags-invisible, sgml-guess-indent):
* textmodes/tex-mode.el (tex-common-initialization)
(latex-complete-bibtex-keys, tex-shell, tex-main-file)
(doctex-mode, plain-tex-mode, latex-mode):
* textmodes/texinfo.el (texinfo-mode): Use setq-local.
2012-12-01 12:09:55 +08:00
|
|
|
|
(setq imenu-create-index-function #'js--imenu-create-index)
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
;; for filling, pretend we're cc-mode
|
|
|
|
|
(setq c-comment-prefix-regexp "//+\\|\\**"
|
2015-07-18 04:01:01 +03:00
|
|
|
|
c-paragraph-start "\\(@[[:alpha:]]+\\>\\|$\\)"
|
2009-08-14 23:02:38 +00:00
|
|
|
|
c-paragraph-separate "$"
|
|
|
|
|
c-block-comment-prefix "* "
|
|
|
|
|
c-line-comment-starter "//"
|
|
|
|
|
c-comment-start-regexp "/[*/]\\|\\s!"
|
|
|
|
|
comment-start-skip "\\(//+\\|/\\*+\\)\\s *")
|
2017-01-09 20:42:43 -07:00
|
|
|
|
(setq-local comment-line-break-function #'c-indent-new-comment-line)
|
|
|
|
|
(setq-local c-block-comment-start-regexp "/\\*")
|
2017-01-17 21:50:14 -07:00
|
|
|
|
(setq-local comment-multi-line t)
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
Convert several major modes to setq-local.
* emacs-lisp/lisp-mode.el (lisp-mode-variables, lisp-mode):
* progmodes/autoconf.el (autoconf-mode):
* progmodes/js.el (js-mode):
* progmodes/make-mode.el (makefile-mode, makefile-makepp-mode)
(makefile-bsdmake-mode, makefile-imake-mode, makefile-browse):
* progmodes/perl-mode.el (perl-mode):
* progmodes/sh-script.el (sh-mode, sh-set-shell):
* textmodes/css-mode.el (css-mode):
* textmodes/sgml-mode.el (html-mode, sgml-mode)
(sgml-tags-invisible, sgml-guess-indent):
* textmodes/tex-mode.el (tex-common-initialization)
(latex-complete-bibtex-keys, tex-shell, tex-main-file)
(doctex-mode, plain-tex-mode, latex-mode):
* textmodes/texinfo.el (texinfo-mode): Use setq-local.
2012-12-01 12:09:55 +08:00
|
|
|
|
(setq-local electric-indent-chars
|
|
|
|
|
(append "{}():;," electric-indent-chars)) ;FIXME: js2-mode adds "[]*".
|
|
|
|
|
(setq-local electric-layout-rules
|
|
|
|
|
'((?\; . after) (?\{ . after) (?\} . before)))
|
2011-08-12 11:32:39 -04:00
|
|
|
|
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(let ((c-buffer-is-cc-mode t))
|
2010-05-02 11:15:29 -04:00
|
|
|
|
;; FIXME: These are normally set by `c-basic-common-init'. Should
|
|
|
|
|
;; we call it instead? (Bug#6071)
|
|
|
|
|
(make-local-variable 'paragraph-start)
|
|
|
|
|
(make-local-variable 'paragraph-separate)
|
|
|
|
|
(make-local-variable 'paragraph-ignore-fill-prefix)
|
|
|
|
|
(make-local-variable 'adaptive-fill-mode)
|
|
|
|
|
(make-local-variable 'adaptive-fill-regexp)
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(c-setup-paragraph-variables))
|
|
|
|
|
|
|
|
|
|
;; Important to fontify the whole buffer syntactically! If we don't,
|
|
|
|
|
;; then we might have regular expression literals that aren't marked
|
|
|
|
|
;; as strings, which will screw up parse-partial-sexp, scan-lists,
|
2011-05-10 15:57:12 +02:00
|
|
|
|
;; etc. and produce maddening "unbalanced parenthesis" errors.
|
2009-08-14 23:02:38 +00:00
|
|
|
|
;; When we attempt to find the error and scroll to the portion of
|
|
|
|
|
;; the buffer containing the problem, JIT-lock will apply the
|
2011-11-17 01:09:20 -08:00
|
|
|
|
;; correct syntax to the regular expression literal and the problem
|
2009-08-14 23:02:38 +00:00
|
|
|
|
;; will mysteriously disappear.
|
2015-08-21 09:03:52 -04:00
|
|
|
|
;; FIXME: We should instead do this fontification lazily by adding
|
Derive from prog-mode, use derived-mode-p, and fix up various
minor style issues in lisp/progmodes.
* lisp/progmodes/vhdl-mode.el (vhdl-write-file-hooks-init)
(vhdl-hs-minor-mode, vhdl-ps-print-init): Fix make-local-variable ->
make-local-hook.
* lisp/progmodes/sh-script.el (sh-require-final-newline): Remove.
(sh-set-shell): Don't set require-final-newline since it's already done
by prog-mode.
* lisp/progmodes/modula2.el (m2-mode): Don't make m2-end-comment-column
since we never set it.
* lisp/progmodes/ebrowse.el (ebrowse-set-tree-indentation):
Use read-string and standard prompt.
* lisp/progmodes/dcl-mode.el (dcl-mode-map): Move init into declaration.
* lisp/progmodes/meta-mode.el (meta-mode-abbrev-table): Merge init and decl.
(meta-common-mode-syntax-table): Rename from meta-mode-syntax-table.
(meta-common-mode-map): Rename from meta-mode-map.
Remove C-m binding, which is a user preference, not mode specific.
(meta-common-mode): New major mode; replace meta-common-initialization.
* lisp/progmodes/js.el (js-mode): Call syntax-propertize rather than messing
around with font-lock.
* lisp/progmodes/etags.el (select-tags-table-mode):
Derive from special-mode.
* lisp/progmodes/octave-mod.el (octave-mode):
* lisp/progmodes/gdb-mi.el (gdb-inferior-io-mode, gdb-threads-mode)
(gdb-memory-mode, gdb-disassembly-mode, gdb-breakpoints-mode)
(gdb-frames-mode, gdb-locals-mode, gdb-registers-mode):
Let define-derived-mode do its job.
* lisp/progmodes/cpp.el (cpp-edit-mode-map):
Move initialization into declaration.
(cpp-edit-mode): Use define-derived-mode.
(cpp-edit-load): Use derived-mode-p.
* lisp/progmodes/mixal-mode.el (mixal-mode):
* lisp/progmodes/f90.el (f90-mode):
* lisp/progmodes/cfengine.el (cfengine-mode): Don't bother setting
require-final-newline since prog-mode does it already.
* lisp/progmodes/cc-cmds.el (c-update-modeline): Use match-string.
* lisp/progmodes/asm-mode.el (asm-mode-map): Fix menu setup.
* lisp/progmodes/antlr-mode.el: Require cc-mode upfront.
(antlr-mode-syntax-table, antlr-action-syntax-table): Initialize in
the declaration.
(antlr-directory-dependencies, antlr-show-makefile-rules):
Use derived-mode-p.
(antlr-language-option): Don't assume point-min==1.
(antlr-mode): Use define-derived-mode.
* lisp/progmodes/ada-mode.el: Use derived-mode-p.
(ada-mode): Use define-derived-mode.
Use hack-local-variables-hook.
* lisp/progmodes/vhdl-mode.el (vhdl-mode):
* lisp/progmodes/verilog-mode.el (verilog-mode):
* lisp/progmodes/vera-mode.el (vera-mode):
* lisp/progmodes/sql.el (sql-mode):
* lisp/progmodes/scheme.el (scheme-mode):
* lisp/progmodes/perl-mode.el (perl-mode):
* lisp/progmodes/octave-inf.el (inferior-octave-mode):
* lisp/progmodes/autoconf.el (autoconf-mode):
* lisp/progmodes/m4-mode.el (m4-mode):
* lisp/progmodes/inf-lisp.el (inferior-lisp-mode):
* lisp/progmodes/idlwave.el (idlwave-mode):
* lisp/progmodes/icon.el (icon-mode):
* lisp/progmodes/idlw-help.el (idlwave-help-mode):
* lisp/progmodes/dcl-mode.el (dcl-mode):
* lisp/progmodes/idlw-shell.el (idlwave-shell-mode):
* lisp/progmodes/ebrowse.el (ebrowse-tree-mode, ebrowse-electric-list-mode)
(ebrowse-member-mode, ebrowse-electric-position-mode):
Use define-derived-mode.
* lisp/progmodes/xscheme.el (xscheme-start)
(local-set-scheme-interaction-buffer, scheme-interaction-mode):
* lisp/progmodes/which-func.el (which-function):
* lisp/progmodes/vhdl-mode.el (vhdl-set-style):
* lisp/progmodes/verilog-mode.el (verilog-set-compile-command)
(verilog-modify-compile-command, verilog-error-regexp-add-xemacs)
(verilog-set-define, verilog-auto-reeval-locals):
* lisp/progmodes/sql.el (sql-product-font-lock, sql-interactive-mode):
* lisp/progmodes/simula.el (simula-mode):
* lisp/progmodes/scheme.el (scheme-mode-variables, dsssl-mode):
* lisp/progmodes/python.el (python-check, python-mode):
* lisp/progmodes/prolog.el (prolog-mode-variables):
* lisp/progmodes/gud.el (gud-tooltip-activate-mouse-motions):
* lisp/progmodes/ebrowse.el (ebrowse-view-file-other-frame):
* lisp/progmodes/delphi.el (delphi-mode):
* lisp/progmodes/cc-styles.el (c-setup-paragraph-variables):
* lisp/progmodes/cc-mode.el (c-basic-common-init, c-common-init)
(c-font-lock-init): Move make-local-variable to their setq.
* lisp/progmodes/xscheme.el (exit-scheme-interaction-mode)
(xscheme-enter-interaction-mode, xscheme-enter-debugger-mode)
(xscheme-debugger-mode-p, xscheme-send-string-1):
* lisp/progmodes/tcl.el (inferior-tcl-proc, tcl-current-word)
(tcl-load-file, tcl-restart-with-file):
* lisp/progmodes/ps-mode.el (ps-run-running):
* lisp/progmodes/gdb-mi.el (gud-watch, gdb-mouse-set-clear-breakpoint):
* lisp/progmodes/js.el (js--get-all-known-symbols):
* lisp/progmodes/inf-lisp.el (inferior-lisp-proc):
* lisp/progmodes/idlwave.el (idlwave-beginning-of-statement)
(idlwave-template, idlwave-update-buffer-routine-info)
(idlwave-update-current-buffer-info)
(idlwave-get-routine-info-from-buffers, idlwave-choose)
(idlwave-scan-class-info, idlwave-fix-keywords)
(idlwave-list-buffer-load-path-shadows):
* lisp/progmodes/idlw-toolbar.el (idlwave-toolbar, idlwave-toolbar-add)
(idlwave-toolbar-remove):
* lisp/progmodes/idlw-shell.el (idlwave-shell-save-and-action)
(idlwave-shell-file-name, idlwave-shell-electric-debug-all-off)
(idlwave-shell-menu-def):
* lisp/progmodes/idlw-complete-structtag.el
(idlwave-prepare-structure-tag-completion):
* lisp/progmodes/gud.el (gud-set-buffer):
* lisp/progmodes/f90.el (f90-backslash-not-special):
* lisp/progmodes/delphi.el (delphi-find-unit): Use derived-mode-p.
2010-12-10 15:00:25 -05:00
|
|
|
|
;; calls to syntax-propertize wherever it's really needed.
|
2015-08-21 09:03:52 -04:00
|
|
|
|
;;(syntax-propertize (point-max))
|
|
|
|
|
)
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
2015-10-30 23:55:24 -07:00
|
|
|
|
;;;###autoload
|
2019-03-23 20:14:29 -07:00
|
|
|
|
(define-derived-mode js-jsx-mode js-mode "JavaScript+JSX"
|
|
|
|
|
"Major mode for editing JavaScript+JSX.
|
|
|
|
|
|
|
|
|
|
Simply makes `js-jsx-syntax' buffer-local and sets it to t.
|
|
|
|
|
|
|
|
|
|
`js-mode' may detect and enable support for JSX automatically if
|
|
|
|
|
it appears to be used in a JavaScript file. You could also
|
|
|
|
|
customize `js-jsx-regexps' to improve that detection; or, you
|
|
|
|
|
could set `js-jsx-syntax' to t in your init file, or in a
|
|
|
|
|
.dir-locals.el file, or using file variables; or, you could call
|
|
|
|
|
`js-jsx-enable' in `js-mode-hook'. You may be better served by
|
|
|
|
|
one of the aforementioned options instead of using this mode."
|
2015-10-30 23:55:24 -07:00
|
|
|
|
:group 'js
|
2019-03-23 20:14:29 -07:00
|
|
|
|
(js-jsx-enable))
|
2015-10-30 23:55:24 -07:00
|
|
|
|
|
2013-01-19 02:22:18 +08:00
|
|
|
|
;;;###autoload (defalias 'javascript-mode 'js-mode)
|
2009-08-14 23:02:38 +00:00
|
|
|
|
|
|
|
|
|
(eval-after-load 'folding
|
|
|
|
|
'(when (fboundp 'folding-add-to-marks-list)
|
|
|
|
|
(folding-add-to-marks-list 'js-mode "// {{{" "// }}}" )))
|
|
|
|
|
|
2014-09-17 10:17:27 +01:00
|
|
|
|
;;;###autoload
|
|
|
|
|
(dolist (name (list "node" "nodejs" "gjs" "rhino"))
|
|
|
|
|
(add-to-list 'interpreter-mode-alist (cons (purecopy name) 'js-mode)))
|
|
|
|
|
|
2009-08-14 23:02:38 +00:00
|
|
|
|
(provide 'js)
|
|
|
|
|
|
|
|
|
|
;; js.el ends here
|