From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Adam Niederer Newsgroups: gmane.emacs.devel Subject: [PATCH] Update js-mode function heading regexes Date: Sat, 17 Jun 2017 03:30:50 -0400 Message-ID: <7ad22b11-406f-1193-c948-faaf01268710@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Trace: blaine.gmane.org 1497686811 10837 195.159.176.226 (17 Jun 2017 08:06:51 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 17 Jun 2017 08:06:51 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Jun 17 10:06:46 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dM8km-0002Mh-8J for ged-emacs-devel@m.gmane.org; Sat, 17 Jun 2017 10:06:44 +0200 Original-Received: from localhost ([::1]:33746 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dM8kp-00058d-VS for ged-emacs-devel@m.gmane.org; Sat, 17 Jun 2017 04:06:48 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58313) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dM8C8-0007hv-9P for emacs-devel@gnu.org; Sat, 17 Jun 2017 03:30:58 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dM8C4-0001V7-Le for emacs-devel@gnu.org; Sat, 17 Jun 2017 03:30:56 -0400 Original-Received: from mail-qt0-x22e.google.com ([2607:f8b0:400d:c0d::22e]:35441) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dM8C4-0001Uo-C2 for emacs-devel@gnu.org; Sat, 17 Jun 2017 03:30:52 -0400 Original-Received: by mail-qt0-x22e.google.com with SMTP id w1so83663401qtg.2 for ; Sat, 17 Jun 2017 00:30:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-transfer-encoding:content-language; bh=bw2ZMgTE6w3bkqeeJZZZSfe+DptBhAD6i40Gc1ci7UU=; b=cZqgAj+pPJIl+w0wLWyoBlhxflfMznSer6C3liQAxYUw9uvV9IdunJei08cMmG3BgT mtl7NX+kx4hT4mXaTUx5jf0OhMMITsAleX3LlmJe8unJACZO5UrbG6w4qVnw9eOHHSkZ WXAWtKKIwHBCMng6i8EA+r9S8TAEq3EFdaW0aUB/rvbngqVRj82pIpOYVpjhiWBlkYRq eexcEmgCYuMUNWU7a66kD0lMLki9Z60Z3/FsDKHjnY2wXILz1SDcLWdZ1JMMrOhaSmtW opdTiLOPehIyvATuL2n7lsrcE9zFzDSSKrFQmUPS8TfY40Mhz/79kCF4cWDcU8veMIKY E7Xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-transfer-encoding:content-language; bh=bw2ZMgTE6w3bkqeeJZZZSfe+DptBhAD6i40Gc1ci7UU=; b=hhCZt5Pi1CqECUOtFGG5LgsANKACdx1N7tNej9fbVaCFLZd5v0nsvaPz9JZ0wnjuHg n0xxU6lUGYbXE4Yc/q5aKiJLcHf3J3MK4TRkKLAFY439i6BGmpHOTBNJ1gzLyJFs+Zo2 rpe3JefA56cdB7fT7cDZtR/QDeGZ5Rpblgrs2baP+N5gnHICISGlbE5DsKIhQqTx/Z+i 6BmE7xlx2y70KT345Ru5T1sOWvaQWtvOvMfqr0ti0uOffTY+Nsa26bQvG54/5XjP2TLk Q3li1xoO681I6Q/XGh6dvUtDIzzaj6RoSIuZY4GvMolWDR9hmiwM/rxuc90W6Fy3lmco nmUA== X-Gm-Message-State: AKS2vOyJ1/Ec58XxiL+M02df1/4kqxDUk2uX+tt9ecwYGtCe69d7oLto Jr7a9GFEqV78BYvxwd4= X-Received: by 10.237.49.41 with SMTP id 38mr16886566qtg.161.1497684651452; Sat, 17 Jun 2017 00:30:51 -0700 (PDT) Original-Received: from [192.168.1.5] (pool-173-59-6-166.phlapa.fios.verizon.net. [173.59.6.166]) by smtp.gmail.com with ESMTPSA id f85sm3475574qkh.6.2017.06.17.00.30.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 17 Jun 2017 00:30:50 -0700 (PDT) Content-Language: en-US X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c0d::22e X-Mailman-Approved-At: Sat, 17 Jun 2017 04:06:13 -0400 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:215689 Archived-At: Hello, I've modified the js-mode function heading regular expressions to accept some modern additions to JavaScript. This causes function names to be highlighted in more cases, and makes js-beginning-of-defun and js-end-of-defun more consistent. The changelog and behavioral changes are as follows: * js--function-heading-1-re - Accept "async function foo" as well as "function foo". This should only affect highlighting. * js--function-heading-2-re - Accept any character before the beginning of a function in an object. This causes the function's name to be correctly highlighted. Pre-patch, beginning-of-defun (C-M-a) with the point in location 1 (below) will place point at the beginning of the function keyword, whereas at location 2 it will place point at the beginning of "bur". Post-patch, beginning-of-defun at location 1 will place point at the beginning of "foo", and at location 2 it will place point at the beginning of "bur" { foo: function() {} bur: function() {} } * js--function-heading-3-re - Accept let, const, and async anonymous functions Pre-patch, beginning-of-defun (C-M-a) with the point in location 1 (below) will place point at the beginning of "x", whereas at locations 2, 3 and 4, it will place point at the beginning of the respective function keywords. Post-patch, beginning-of-defun (C-M-a) with the point in location 1 (below) will place point at the beginning of "x", whereas at location 2, 3 and 4, it will place point at the beginning of "y", "z" and "w", respectively. var x = function() {} var y = async function() {} let z = function() {} let w = async function() {} Below is the file I used to test these changes. make check is failing for me, but it looks like the failing tests are unrelated (filenotify & inotify). This is my first contribution via a mailing list, so please let me know if I'm missing anything :). -Adam { foo: function() {} bar: function() {} } [{ foo: function() {} bar: function() {} }] let x = [{ foo: function() {} bar: function() {} }] function foo() {} async function bar() {} var x = function() {} var x = async function() {} let x = function() {} let x = async function() {} const x = function() {} const x = async function() {} diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el index bae9e52bf0..126181f5bb 100644 --- a/lisp/progmodes/js.el +++ b/lisp/progmodes/js.el @@ -250,20 +250,20 @@ js--available-frameworks (defconst js--function-heading-1-re (concat - "^\\s-*function\\(?:\\s-\\|\\*\\)+\\(" js--name-re "\\)") + "^\\s-*\\(?:async\\s-+\\)?function\\(?:\\s-\\|\\*\\)+\\(" js--name-re "\\)") "Regexp matching the start of a JavaScript function header. Match group 1 is the name of the function.") (defconst js--function-heading-2-re (concat - "^\\s-*\\(" js--name-re "\\)\\s-*:\\s-*function\\_>") + "^.*?\\(" js--name-re "\\)\\s-*:\\s-*function\\_>") "Regexp matching the start of a function entry in an associative array. Match group 1 is the name of the function.") (defconst js--function-heading-3-re (concat - "^\\s-*\\(?:var\\s-+\\)?\\(" js--dotted-name-re "\\)" - "\\s-*=\\s-*function\\_>") + "^\\s-*\\(?:\\(?:var\\|let\\|const\\)\\s-+\\)?\\(" js--dotted-name-re "\\)" + "\\s-*=\\s-*\\(?:async\\s-+\\)?function\\_>") "Regexp matching a line in the JavaScript form \"var MUMBLE = function\". Match group 1 is MUMBLE.")