From 0f053e21f29af4566b63000834d4ca5079277f2a Mon Sep 17 00:00:00 2001 From: Tom Browder Date: Wed, 27 Jul 2016 17:09:04 -0500 Subject: [PATCH 01/18] now have a working solution for an Index imenu for subs and vars --- perl6-imenu.el | 40 ++++++++++++++++++++++++++++++++++++++++ perl6-mode.el | 3 ++- 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 perl6-imenu.el diff --git a/perl6-imenu.el b/perl6-imenu.el new file mode 100644 index 0000000..8918449 --- /dev/null +++ b/perl6-imenu.el @@ -0,0 +1,40 @@ +;;; perl6-imenu.el --- Imenu support Perl 6 -*- lexical-binding: t; -*- + +;;; Commentary: + + +;; Imenu functions and variables are defined here. +(defvar perl6-imenu-generic-expression + '( + ;; the names are in reverse desired order since they are evaluated here last first + ("Variables" "^\\s-*\\(?:my\\|our\\)\\s-+\\(\\(?:\\$\\|@\\|%\\)\\(?:[_[:alnum:]]+\\)\\)" 1) + ("Subs/Methods" "^\\s-*\\(?:my\\|our\\)\\s-+\\(?:sub\\|method\\|multi-method\\)\\s-+\\(.+)\\)" 1) + ) + "Define interesting points in the Perl 6 buffer for `imenu'. + +This is used to set `imenu-generic-expression' when Perl 6 mode is +entered. Subsequent changes to `perl6-imenu-generic-expression' will +not affect existing Perl 6 buffers because imenu-generic-expression is +a local variable.") + +;; Add imenu support for perl6-mode. Note that imenu-generic-expression +;; is buffer-local, so we don't need a local-variable for it. +(setq imenu-generic-expression perl6-imenu-generic-expression + imenu-case-fold-search nil) + +;; Imenu support +(setq imenu-auto-rescan t) +(add-hook 'perl6-mode-hook 'imenu-add-menubar-index) +(add-hook 'perl6-mode-hook + (lambda () + (setq imenu-generic-expression perl6-imenu-generic-expression))) + +;;=========================== +(provide 'perl6-imenu) + +;; Local Variables: +;; coding: utf-8 +;; indent-tabs-mode: nil +;; End: + +;;; perl6-imenu.el ends here diff --git a/perl6-mode.el b/perl6-mode.el index 67c5853..25538da 100644 --- a/perl6-mode.el +++ b/perl6-mode.el @@ -41,6 +41,7 @@ (require 'perl6-detect) (require 'perl6-font-lock) (require 'perl6-indent) +(require 'perl6-imenu) ;;;###autoload (define-derived-mode perl6-mode prog-mode "Perl6" @@ -55,7 +56,7 @@ (setq-local comment-start-skip "#+ *") (setq-local comment-use-syntax t) (setq-local comment-end "") - ;; Indentation + ;; Indentation (smie-setup perl6-smie-grammar #'perl6-smie-rules :forward-token #'perl6-smie--forward-token :backward-token #'perl6-smie--backward-token)) From 8319cebe758fa067df149f991e79096afbb6a412 Mon Sep 17 00:00:00 2001 From: Tom Browder Date: Wed, 27 Jul 2016 17:11:13 -0500 Subject: [PATCH 02/18] remove imenu item --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 9c482b1..77511ad 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,6 @@ This mode needs GNU Emacs 24.4. * Better indentation support * Help system * REPL interaction -* imenu support * ETags support * `find-file-at-point` for module names * Electricity (`electric-pair-mode` needs some context-sensitive help) From 309720c98a5b8a9f35e48e05697a18fdd211fc0a Mon Sep 17 00:00:00 2001 From: Tom Browder Date: Wed, 27 Jul 2016 17:14:14 -0500 Subject: [PATCH 03/18] correct indentation --- perl6-mode.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/perl6-mode.el b/perl6-mode.el index 25538da..0350cd9 100644 --- a/perl6-mode.el +++ b/perl6-mode.el @@ -56,7 +56,7 @@ (setq-local comment-start-skip "#+ *") (setq-local comment-use-syntax t) (setq-local comment-end "") - ;; Indentation + ;; Indentation (smie-setup perl6-smie-grammar #'perl6-smie-rules :forward-token #'perl6-smie--forward-token :backward-token #'perl6-smie--backward-token)) From 89d6145859c3c4d372a2dc8c809ee18267128388 Mon Sep 17 00:00:00 2001 From: Tom Browder Date: Wed, 27 Jul 2016 20:18:14 -0500 Subject: [PATCH 04/18] use proper name for a multi sub or method --- perl6-imenu.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/perl6-imenu.el b/perl6-imenu.el index 8918449..3e30987 100644 --- a/perl6-imenu.el +++ b/perl6-imenu.el @@ -8,7 +8,7 @@ '( ;; the names are in reverse desired order since they are evaluated here last first ("Variables" "^\\s-*\\(?:my\\|our\\)\\s-+\\(\\(?:\\$\\|@\\|%\\)\\(?:[_[:alnum:]]+\\)\\)" 1) - ("Subs/Methods" "^\\s-*\\(?:my\\|our\\)\\s-+\\(?:sub\\|method\\|multi-method\\)\\s-+\\(.+)\\)" 1) + ("Subs/Methods" "^\\s-*\\(?:my\\|our\\)\\s-+\\(?:sub\\|method\\|multi\\)\\s-+\\(.+)\\)" 1) ) "Define interesting points in the Perl 6 buffer for `imenu'. From c8e8ebe289afb1b085d813f3e6b038ae15b0f00f Mon Sep 17 00:00:00 2001 From: Tom Browder Date: Wed, 27 Jul 2016 20:29:18 -0500 Subject: [PATCH 05/18] fix the range of choices more completely --- perl6-imenu.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/perl6-imenu.el b/perl6-imenu.el index 3e30987..d204289 100644 --- a/perl6-imenu.el +++ b/perl6-imenu.el @@ -8,7 +8,7 @@ '( ;; the names are in reverse desired order since they are evaluated here last first ("Variables" "^\\s-*\\(?:my\\|our\\)\\s-+\\(\\(?:\\$\\|@\\|%\\)\\(?:[_[:alnum:]]+\\)\\)" 1) - ("Subs/Methods" "^\\s-*\\(?:my\\|our\\)\\s-+\\(?:sub\\|method\\|multi\\)\\s-+\\(.+)\\)" 1) + ("Subs/Methods" "^\\s-*\\(?:my\\|our\\)\\s-+\\(?:sub\\|method\\|multi\\|multi\\s-+sub\\|multi\\s-+method:\\)\\s-+\\(.+)\\)" 1) ) "Define interesting points in the Perl 6 buffer for `imenu'. From 07b596cab62501aee9a448055bff3969d1342883 Mon Sep 17 00:00:00 2001 From: Tom Browder Date: Thu, 28 Jul 2016 07:00:07 -0500 Subject: [PATCH 06/18] one more tweak to catch all forms of subs --- perl6-imenu.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/perl6-imenu.el b/perl6-imenu.el index d204289..0aea6ca 100644 --- a/perl6-imenu.el +++ b/perl6-imenu.el @@ -8,7 +8,7 @@ '( ;; the names are in reverse desired order since they are evaluated here last first ("Variables" "^\\s-*\\(?:my\\|our\\)\\s-+\\(\\(?:\\$\\|@\\|%\\)\\(?:[_[:alnum:]]+\\)\\)" 1) - ("Subs/Methods" "^\\s-*\\(?:my\\|our\\)\\s-+\\(?:sub\\|method\\|multi\\|multi\\s-+sub\\|multi\\s-+method:\\)\\s-+\\(.+)\\)" 1) + ("Subs/Methods" "^\\s-*\\(?:my\\s-+\\|our\\s-+\\)?\\(?:multi\\s-+sub\\|multi\\s-+method\\|sub\\|method\\|multi\\)\\s-+\\(.+)\\)" 1) ) "Define interesting points in the Perl 6 buffer for `imenu'. From 8f230b887fdf74a1b4ce9c7075f0d51813073f68 Mon Sep 17 00:00:00 2001 From: Tom Browder Date: Fri, 29 Jul 2016 12:01:20 -0500 Subject: [PATCH 07/18] remove user option per syohex's comment --- perl6-imenu.el | 1 - 1 file changed, 1 deletion(-) diff --git a/perl6-imenu.el b/perl6-imenu.el index 0aea6ca..f6211c7 100644 --- a/perl6-imenu.el +++ b/perl6-imenu.el @@ -23,7 +23,6 @@ a local variable.") imenu-case-fold-search nil) ;; Imenu support -(setq imenu-auto-rescan t) (add-hook 'perl6-mode-hook 'imenu-add-menubar-index) (add-hook 'perl6-mode-hook (lambda () From 0bd2a0966359668c2ef96494bf85ebfea7ec3f9a Mon Sep 17 00:00:00 2001 From: Tom Browder Date: Fri, 29 Jul 2016 12:19:57 -0500 Subject: [PATCH 08/18] add vars moved from perl6-imenu.el per comments from syohex --- perl6-mode.el | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/perl6-mode.el b/perl6-mode.el index 0350cd9..d5b2d24 100644 --- a/perl6-mode.el +++ b/perl6-mode.el @@ -51,6 +51,11 @@ (add-hook 'syntax-propertize-extend-region-functions #'syntax-propertize-multiline nil 'local) (setq-local font-lock-syntactic-face-function #'perl6-font-lock-syntactic-face) (setq-local font-lock-defaults '(perl6-font-lock-keywords nil nil)) + ;; Add imenu support for perl6-mode. Note that imenu-generic-expression + ;; is buffer-local, so we don't need a local-variable for it. + (add-hook 'perl6-mode-hook 'imenu-add-menubar-index) + (setq imenu-generic-expression perl6-imenu-generic-expression + imenu-case-fold-search nil) ;; Comments (setq-local comment-start "#") (setq-local comment-start-skip "#+ *") From 81805cfa8e1ddc4eafa1381264b6f41d695cbba9 Mon Sep 17 00:00:00 2001 From: Tom Browder Date: Fri, 29 Jul 2016 12:21:20 -0500 Subject: [PATCH 09/18] remove vars (to main file) per comments from syohex, clean up some --- perl6-imenu.el | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/perl6-imenu.el b/perl6-imenu.el index f6211c7..55a9477 100644 --- a/perl6-imenu.el +++ b/perl6-imenu.el @@ -1,33 +1,19 @@ ;;; perl6-imenu.el --- Imenu support Perl 6 -*- lexical-binding: t; -*- -;;; Commentary: - - ;; Imenu functions and variables are defined here. (defvar perl6-imenu-generic-expression - '( - ;; the names are in reverse desired order since they are evaluated here last first - ("Variables" "^\\s-*\\(?:my\\|our\\)\\s-+\\(\\(?:\\$\\|@\\|%\\)\\(?:[_[:alnum:]]+\\)\\)" 1) - ("Subs/Methods" "^\\s-*\\(?:my\\s-+\\|our\\s-+\\)?\\(?:multi\\s-+sub\\|multi\\s-+method\\|sub\\|method\\|multi\\)\\s-+\\(.+)\\)" 1) - ) - "Define interesting points in the Perl 6 buffer for `imenu'. + '( + ;; the names are in reverse desired order since they are evaluated here last first + ("Variables" "^\\s-*\\(?:my\\|our\\)\\s-+\\(\\(?:\\$\\|@\\|%\\)\\(?:[_[:alnum:]]+\\)\\)" 1) + ("Subs/Methods" "^\\s-*\\(?:my\\s-+\\|our\\s-+\\)?\\(?:multi\\s-+sub\\|multi\\s-+method\\|sub\\|method\\|multi\\)\\s-+\\(.+)\\)" 1) + ) + "Define interesting points in the Perl 6 buffer for `imenu'. This is used to set `imenu-generic-expression' when Perl 6 mode is entered. Subsequent changes to `perl6-imenu-generic-expression' will not affect existing Perl 6 buffers because imenu-generic-expression is a local variable.") -;; Add imenu support for perl6-mode. Note that imenu-generic-expression -;; is buffer-local, so we don't need a local-variable for it. -(setq imenu-generic-expression perl6-imenu-generic-expression - imenu-case-fold-search nil) - -;; Imenu support -(add-hook 'perl6-mode-hook 'imenu-add-menubar-index) -(add-hook 'perl6-mode-hook - (lambda () - (setq imenu-generic-expression perl6-imenu-generic-expression))) - ;;=========================== (provide 'perl6-imenu) From 385ed1d54ac6fe1cc75e163cefab271cb369d510 Mon Sep 17 00:00:00 2001 From: Tom Browder Date: Fri, 29 Jul 2016 14:40:10 -0500 Subject: [PATCH 10/18] pull regexes up into documents variables, add index of classes, update regexes a bit (no longer show sub signatures) --- perl6-imenu.el | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/perl6-imenu.el b/perl6-imenu.el index 55a9477..9681820 100644 --- a/perl6-imenu.el +++ b/perl6-imenu.el @@ -1,12 +1,48 @@ ;;; perl6-imenu.el --- Imenu support Perl 6 -*- lexical-binding: t; -*- ;; Imenu functions and variables are defined here. + +;; TODO: tighten regexes to distinguish correct naming for Perl 6 +;; vs. NQP (make a minor mode?) + +;; Regex definitions: +(defvar perl6-vars-regex + (concat + "^\\s-*" ; leading ws allowed + "\\(?:my\\|our\\)\\s-+" ; scope of var, followed by mandatory ws + "\\(" ; start capture group 1 for the var name + "\\(?:\\$\\|@\\|%\\)" ; sigil for type of var + "\\(?:[-_[:alnum:]]+\\)" ; the var name ends with ws + "\\)" ; end of capture group 1 + )) + +(defvar perl6-subs-regex + (concat + "^\\s-*" ; leading ws allowed + "\\(?:my\\s-+\\|our\\s-+\\)?" ; optional specific scope followed by at least one space + ; must have one of the five type identifiers followed by at least one space: + "\\(?:multi\\s-+sub\\|multi\\s-+method\\|sub\\|method\\|multi\\|proto\\)\\s-+" + "\\([-_[:alnum:]]+\\)" ; the capture group of the sub name + )) + +(defvar perl6-classes-regex + (concat + "^\\s-*" ; leading ws allowed + ; must have one of the four type identifiers followed by at least one space: + "class\\s-+" + "\\([-_[:alnum:]]+\\)" ; the capture group of the sub name + ;"[\\n\\s\\-{]+" ; ended by whitespace or an opening curly brace' + )) + (defvar perl6-imenu-generic-expression - '( - ;; the names are in reverse desired order since they are evaluated here last first - ("Variables" "^\\s-*\\(?:my\\|our\\)\\s-+\\(\\(?:\\$\\|@\\|%\\)\\(?:[_[:alnum:]]+\\)\\)" 1) - ("Subs/Methods" "^\\s-*\\(?:my\\s-+\\|our\\s-+\\)?\\(?:multi\\s-+sub\\|multi\\s-+method\\|sub\\|method\\|multi\\)\\s-+\\(.+)\\)" 1) - ) + `( + ;; the names are in reverse desired order since they are evaluated here last first + ;("Variables" "^\\s-*\\(?:my\\|our\\)\\s-+\\(\\(?:\\$\\|@\\|%\\)\\(?:[_[:alnum:]]+\\)\\)" 1) + ("Classes" ,perl6-classes-regex 1) + ("Variables" ,perl6-vars-regex 1) + ;;("Subs/Methods" "^\\s-*\\(?:my\\s-+\\|our\\s-+\\)?\\(?:multi\\s-+sub\\|multi\\s-+method\\|sub\\|method\\|multi\\)\\s-+\\(.+)\\)" 1) + ("Subs/Methods" ,perl6-subs-regex 1) + ) "Define interesting points in the Perl 6 buffer for `imenu'. This is used to set `imenu-generic-expression' when Perl 6 mode is From 298b6bb51c5a70fe3189a9976986aff2a55fd960 Mon Sep 17 00:00:00 2001 From: Tom Browder Date: Fri, 29 Jul 2016 14:40:42 -0500 Subject: [PATCH 11/18] add a test file for aiding regex development --- test/test-imenu.p6 | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 test/test-imenu.p6 diff --git a/test/test-imenu.p6 b/test/test-imenu.p6 new file mode 100644 index 0000000..f63cf73 --- /dev/null +++ b/test/test-imenu.p6 @@ -0,0 +1,21 @@ +# file: test-imenu.p6 + +# Perl 6 syntax file for testing perl6-mode with imenu support, which is located at: +# +# https://github.com/tbrowder/perl6-mode [branch: "my-branch"] + +my $a; +my @b; +our %c; + + sub a(){my @ze} + multi sub x() {} +method d() {} +my multi method z() {} +multi c() {} + +proto xx() {} + +class My-class1 +class My-class2{ + class doit ( From 4b012444900aeaed0c5c1633869f71ba28546e9f Mon Sep 17 00:00:00 2001 From: Tom Browder Date: Fri, 29 Jul 2016 15:25:41 -0500 Subject: [PATCH 12/18] make this work for nqp also --- perl6-detect.el | 1 + 1 file changed, 1 insertion(+) diff --git a/perl6-detect.el b/perl6-detect.el index 575ba64..5753144 100644 --- a/perl6-detect.el +++ b/perl6-detect.el @@ -14,6 +14,7 @@ ;;;###autoload (add-to-list 'auto-mode-alist '("\\.p[lm]?6\\'" . perl6-mode)) +(add-to-list 'auto-mode-alist '("\\.nqp\\'" . perl6-mode)) ;;;###autoload (defconst perl6-magic-pattern From 4f1e2928d2c56732dea509a758a065acf477f72c Mon Sep 17 00:00:00 2001 From: Tom Browder Date: Sat, 30 Jul 2016 07:12:42 -0500 Subject: [PATCH 13/18] add more generalization with more defined regexes, remove commented out old code --- perl6-imenu.el | 71 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 20 deletions(-) diff --git a/perl6-imenu.el b/perl6-imenu.el index 9681820..68f1a9b 100644 --- a/perl6-imenu.el +++ b/perl6-imenu.el @@ -2,45 +2,76 @@ ;; Imenu functions and variables are defined here. -;; TODO: tighten regexes to distinguish correct naming for Perl 6 -;; vs. NQP (make a minor mode?) +;; Definition of "identifiers" (names) from +;; https://docs.perl6.org/language/syntax#Identifiers +;; +;; Identifiers are a grammatical building block that occur in several +;; places. An identifier is a primitive name, and must start with an +;; alphabetic character (or an underscore), followed by zero or more +;; word characters (alphabetic, underscore or number). You can also +;; embed dashes - or single quotes ' in the middle, but not two in a +;; row, and only if followed immediately by an alphabetic character. +;; +;; For NQP names, no embedded hyphens or single quotes are allowed. ;; Regex definitions: +(defvar perl6-name-regex + (concat + "[_[:alpha:]]" ; mandatory leading character + "\\(?:[-']?[[:alpha:]]\\|[_[:alnum:]]\\)*" ; rest of the name allowing embedded hyphens or single quotes + )) + +(defvar nqp-name-regex + (concat + "[_[:alpha:]]" ; mandatory leading character + "[_[:alnum:]]*" ; rest of the name (stricter than Perl 6 name) + )) + (defvar perl6-vars-regex (concat - "^\\s-*" ; leading ws allowed - "\\(?:my\\|our\\)\\s-+" ; scope of var, followed by mandatory ws - "\\(" ; start capture group 1 for the var name - "\\(?:\\$\\|@\\|%\\)" ; sigil for type of var - "\\(?:[-_[:alnum:]]+\\)" ; the var name ends with ws - "\\)" ; end of capture group 1 + "^\\s-*" ; leading ws allowed + "\\(?:my\\|our\\)\\s-+" ; scope of var, followed by mandatory ws + "\\(" ; start capture group 1 for the var name + "\\(?:\\$\\|@\\|%\\)" ; sigil for type of var + "\\(?:" ; start shy group for choice of one type name + perl6-name-regex + "\\|" + nqp-name-regex + "\\)" ; end shy group + "\\)" ; end of capture group 1 )) (defvar perl6-subs-regex (concat - "^\\s-*" ; leading ws allowed - "\\(?:my\\s-+\\|our\\s-+\\)?" ; optional specific scope followed by at least one space - ; must have one of the five type identifiers followed by at least one space: - "\\(?:multi\\s-+sub\\|multi\\s-+method\\|sub\\|method\\|multi\\|proto\\)\\s-+" - "\\([-_[:alnum:]]+\\)" ; the capture group of the sub name + "^\\s-*" ; leading ws allowed + "\\(?:my\\s-+\\|our\\s-+\\)?" ; optional specific scope followed by at least one space + ; must have one of the five type identifiers + ; followed by at least one space: + "\\(?:multi\\s-+sub\\|multi\\s-+method\\|sub\\|method\\|multi\\|proto\\)\\s-+" + "\\(" ; start capture group 1 for the sub name + perl6-name-regex + "\\|" + nqp-name-regex + "\\)" ; end of capture group 1 )) (defvar perl6-classes-regex (concat - "^\\s-*" ; leading ws allowed - ; must have one of the four type identifiers followed by at least one space: - "class\\s-+" - "\\([-_[:alnum:]]+\\)" ; the capture group of the sub name - ;"[\\n\\s\\-{]+" ; ended by whitespace or an opening curly brace' + "^\\s-*" ; leading ws allowed + ; must have one of the four type identifiers followed by at least one space: + "class\\s-+" + "\\(" ; start capture group 1 of the class name + perl6-name-regex + "\\|" + nqp-name-regex + "\\)" ; end of capture group 1 )) (defvar perl6-imenu-generic-expression `( ;; the names are in reverse desired order since they are evaluated here last first - ;("Variables" "^\\s-*\\(?:my\\|our\\)\\s-+\\(\\(?:\\$\\|@\\|%\\)\\(?:[_[:alnum:]]+\\)\\)" 1) ("Classes" ,perl6-classes-regex 1) ("Variables" ,perl6-vars-regex 1) - ;;("Subs/Methods" "^\\s-*\\(?:my\\s-+\\|our\\s-+\\)?\\(?:multi\\s-+sub\\|multi\\s-+method\\|sub\\|method\\|multi\\)\\s-+\\(.+)\\)" 1) ("Subs/Methods" ,perl6-subs-regex 1) ) "Define interesting points in the Perl 6 buffer for `imenu'. From f3256bb3fd20ff2d080fa8aa465edcd2e1e38327 Mon Sep 17 00:00:00 2001 From: Tom Browder Date: Sat, 30 Jul 2016 07:14:34 -0500 Subject: [PATCH 14/18] add some more test names --- test/test-imenu.p6 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/test-imenu.p6 b/test/test-imenu.p6 index f63cf73..307bd42 100644 --- a/test/test-imenu.p6 +++ b/test/test-imenu.p6 @@ -8,6 +8,9 @@ my $a; my @b; our %c; +my $a-a; +my $a'a_3-z; + sub a(){my @ze} multi sub x() {} method d() {} @@ -16,6 +19,6 @@ multi c() {} proto xx() {} -class My-class1 +class My-class1 {} class My-class2{ - class doit ( + class doit () {} From 47cda8e4302a315a6648a3293fd01347f60843f6 Mon Sep 17 00:00:00 2001 From: Tom Browder Date: Tue, 13 Sep 2016 04:34:53 -0500 Subject: [PATCH 15/18] add optional leading bang for private method names --- perl6-imenu.el | 1 + 1 file changed, 1 insertion(+) diff --git a/perl6-imenu.el b/perl6-imenu.el index 68f1a9b..075b634 100644 --- a/perl6-imenu.el +++ b/perl6-imenu.el @@ -48,6 +48,7 @@ ; must have one of the five type identifiers ; followed by at least one space: "\\(?:multi\\s-+sub\\|multi\\s-+method\\|sub\\|method\\|multi\\|proto\\)\\s-+" + "\\!?" ; optional private marker "\\(" ; start capture group 1 for the sub name perl6-name-regex "\\|" From 992d8af9de0263a9d35d623e1af43c3cdd938bcf Mon Sep 17 00:00:00 2001 From: Tom Browder Date: Tue, 13 Sep 2016 04:37:06 -0500 Subject: [PATCH 16/18] add test for private methods --- test/test-imenu.p6 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test-imenu.p6 b/test/test-imenu.p6 index 307bd42..5ec9e41 100644 --- a/test/test-imenu.p6 +++ b/test/test-imenu.p6 @@ -16,8 +16,8 @@ my $a'a_3-z; method d() {} my multi method z() {} multi c() {} - proto xx() {} +multi method !z-private() {} class My-class1 {} class My-class2{ From d33d36e0851291ac5018b05556f11e3ada346a42 Mon Sep 17 00:00:00 2001 From: Tom Browder Date: Tue, 13 Sep 2016 04:40:12 -0500 Subject: [PATCH 17/18] add test for nqp --- test/test-imenu.nqp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 test/test-imenu.nqp diff --git a/test/test-imenu.nqp b/test/test-imenu.nqp new file mode 100644 index 0000000..307bd42 --- /dev/null +++ b/test/test-imenu.nqp @@ -0,0 +1,24 @@ +# file: test-imenu.p6 + +# Perl 6 syntax file for testing perl6-mode with imenu support, which is located at: +# +# https://github.com/tbrowder/perl6-mode [branch: "my-branch"] + +my $a; +my @b; +our %c; + +my $a-a; +my $a'a_3-z; + + sub a(){my @ze} + multi sub x() {} +method d() {} +my multi method z() {} +multi c() {} + +proto xx() {} + +class My-class1 {} +class My-class2{ + class doit () {} From 588dc4417bcb225b55c297742c93607dc317efe4 Mon Sep 17 00:00:00 2001 From: Tom Browder Date: Tue, 13 Sep 2016 04:52:20 -0500 Subject: [PATCH 18/18] add new files --- README.tmp-imenu-notes | 53 +++++++++++++++++++++++++++++ nqp-mode.el | 76 ++++++++++++++++++++++++++++++++++++++++++ perl6-unicode-menu.el | 30 +++++++++++++++++ 3 files changed, 159 insertions(+) create mode 100644 README.tmp-imenu-notes create mode 100644 nqp-mode.el create mode 100644 perl6-unicode-menu.el diff --git a/README.tmp-imenu-notes b/README.tmp-imenu-notes new file mode 100644 index 0000000..60d3374 --- /dev/null +++ b/README.tmp-imenu-notes @@ -0,0 +1,53 @@ +major modes: + +The mode should specify how Imenu should find the definitions or +sections of a buffer, by setting up a buffer-local value for the +variable imenu-generic-expression, for the two variables +imenu-prev-index-position-function and +imenu-extract-index-name-function, or for the variable +imenu-create-index-function (see Imenu). + +Macro: defvar-local variable value &optional docstring + + This macro defines variable as a variable with initial value value + and docstring, and marks it as automatically buffer-local. It is + equivalent to calling defvar followed by + make-variable-buffer-local. variable should be an unquoted symbol. + +22.5 Imenu + +Imenu is a feature that lets users select a definition or section in +the buffer, from a menu which lists all of them, to go directly to +that location in the buffer. Imenu works by constructing a buffer +index which lists the names and buffer positions of the definitions, +or other named portions of the buffer; then the user can choose one of +them and move point to it. Major modes can add a menu bar item to use +Imenu using imenu-add-to-menubar. + +Command: imenu-add-to-menubar name + + This function defines a local menu bar item named name to run Imenu. + +The usual and simplest way is to set the variable imenu-generic-expression: + +Variable: imenu-generic-expression + + This variable, if non-nil, is a list that specifies regular + expressions for finding definitions for Imenu. Simple elements of + imenu-generic-expression look like this: + + (menu-title regexp index) + + Here, if menu-title is non-nil, it says that the matches for this + element should go in a submenu of the buffer index; menu-title + itself specifies the name for the submenu. If menu-title is nil, the + matches for this element go directly in the top level of the buffer + index. + + The second item in the list, regexp, is a regular expression (see + Regular Expressions); anything in the buffer that it matches is + considered a definition, something to mention in the buffer + index. + + The third item, index, is a non-negative integer that indicates + which subexpression in regexp matches the definition’s name. diff --git a/nqp-mode.el b/nqp-mode.el new file mode 100644 index 0000000..d5b2d24 --- /dev/null +++ b/nqp-mode.el @@ -0,0 +1,76 @@ +;;; perl6-mode.el --- Major mode for editing Perl 6 code -*- lexical-binding: t; -*- + +;; Copyright (C) 2015 Hinrik Örn Sigurðsson + +;; Author: Hinrik Örn Sigurðsson +;; URL: https://github.com/hinrik/perl6-mode +;; Keywords: languages +;; Version: 0.1-git +;; Package-Requires: ((emacs "24.4") (pkg-info "0.1")) + +;; This file is not part of GNU Emacs. + +;; This program 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. + +;; This program 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 +;; along with this program. If not, see . + +;;; Commentary: + +;; GNU Emacs 24 major mode for editing Perl 6 code. + +;; Currently only provides very basic syntax highlighting. + +;;; Code: + +(declare-function pkg-info-version-info "pkg-info" (library)) + +(defgroup perl6 nil + "Major mode for editing Perl 6 code." + :prefix "perl6-" + :group 'language) + +(require 'perl6-detect) +(require 'perl6-font-lock) +(require 'perl6-indent) +(require 'perl6-imenu) + +;;;###autoload +(define-derived-mode perl6-mode prog-mode "Perl6" + "Major mode for editing Perl 6 code." + ;; Syntaxification and font locking + (setq-local syntax-propertize-function #'perl6-syntax-propertize) + (add-hook 'syntax-propertize-extend-region-functions #'syntax-propertize-multiline nil 'local) + (setq-local font-lock-syntactic-face-function #'perl6-font-lock-syntactic-face) + (setq-local font-lock-defaults '(perl6-font-lock-keywords nil nil)) + ;; Add imenu support for perl6-mode. Note that imenu-generic-expression + ;; is buffer-local, so we don't need a local-variable for it. + (add-hook 'perl6-mode-hook 'imenu-add-menubar-index) + (setq imenu-generic-expression perl6-imenu-generic-expression + imenu-case-fold-search nil) + ;; Comments + (setq-local comment-start "#") + (setq-local comment-start-skip "#+ *") + (setq-local comment-use-syntax t) + (setq-local comment-end "") + ;; Indentation + (smie-setup perl6-smie-grammar #'perl6-smie-rules + :forward-token #'perl6-smie--forward-token + :backward-token #'perl6-smie--backward-token)) + +(provide 'perl6-mode) + +;; Local Variables: +;; coding: utf-8 +;; indent-tabs-mode: nil +;; End: + +;;; perl6-mode.el ends here diff --git a/perl6-unicode-menu.el b/perl6-unicode-menu.el new file mode 100644 index 0000000..b4a87e7 --- /dev/null +++ b/perl6-unicode-menu.el @@ -0,0 +1,30 @@ +;; Provide a menu bar item to ease insertion of Unicode characters. + + +;; Make a menu keymap (with a prompt string) +;; and make it the menu bar item’s definition. +;; put it at the end +(define-key global-map [menu-bar unicode] + (cons "Unicode" (make-sparse-keymap "Unicode"))) +;; Define specific subcommands in this menu. +(define-key global-map + [menu-bar unicode forward] + '("Forward word" . forward-word)) +(define-key global-map + [menu-bar unicode backward] + '("Backward word" . backward-word)) +(defvar menu-bar-final-items '(help-menu unicode-menu)) ;; doesn't work?? + + + + + +;;=========================== +(provide 'perl6-unicode-menu) + +;; Local Variables: +;; coding: utf-8 +;; indent-tabs-mode: nil +;; End: + +;;; perl6-imenu.el ends here