[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/raku-mode 6fa383e25f 003/253: More robust magic matching o
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/raku-mode 6fa383e25f 003/253: More robust magic matching of Perl 6 code |
Date: |
Sat, 29 Jan 2022 08:28:34 -0500 (EST) |
branch: elpa/raku-mode
commit 6fa383e25f8063332274765b02604393e7610f69
Author: Hinrik Örn Sigurðsson <hinrik.sig@gmail.com>
Commit: Hinrik Örn Sigurðsson <hinrik.sig@gmail.com>
More robust magic matching of Perl 6 code
Now we require the first line of code (non-comment, non-whitespace)
in the file to be Perl 6.
This avoids matching Perl 5 files that contain 'class' keywords after
loading a module that makes that keyword available.
---
perl6-mode.el | 30 +++++++++++++++++++++++-------
1 file changed, 23 insertions(+), 7 deletions(-)
diff --git a/perl6-mode.el b/perl6-mode.el
index 1840e7a451..7ff958a322 100644
--- a/perl6-mode.el
+++ b/perl6-mode.el
@@ -58,15 +58,31 @@
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.p[lm]?6\\'" . perl6-mode))
-(defvar perl6--content-pattern
- "^ *\\(?:use +v6\\|\\(?:\\(?:my\\|our\\)
+\\)?\\(?:module\\|class\\|role\\|grammar\\)\\)")
+(defvar perl6-magic-pattern
+ (rx line-start
+ (0+ space)
+ (or (and "use" (0+ space) "v6")
+ (and (opt (and (or "my" "our") (0+ space)))
+ (or "module" "class" "role" "grammar")))))
+
+(defun perl6-magic-matcher ()
+ "Return non-nil if the current buffer is probably a Perl 6 file."
+ (let ((case-fold-search nil)
+ (keep-going t)
+ (found-perl6 nil))
+ (while keep-going
+ (cond ((looking-at "^ *\\(?:#.*\\)?$")
+ nil)
+ ((looking-at perl6-magic-pattern)
+ (setq keep-going nil
+ found-perl6 t))
+ (t
+ (setq keep-going nil)))
+ (beginning-of-line 2))
+ found-perl6))
;;;###autoload
-(add-to-list 'magic-mode-alist '((lambda ()
- (and
- (and (stringp buffer-file-name)
- (string-match
"\\.\\(?:t\\|p[lm]\\)\\'" buffer-file-name))
- (re-search-forward perl6--content-pattern
4096 t))) . perl6-mode))
+(add-to-list 'magic-mode-alist '(perl6-magic-matcher . perl6-mode))
(provide 'perl6-mode)
- [nongnu] elpa/raku-mode 3ae6b19b24 235/253: Make keybindings more understandable, (continued)
- [nongnu] elpa/raku-mode 3ae6b19b24 235/253: Make keybindings more understandable, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 357a72be71 229/253: Fix syntax highlighting for code blocks in POD., ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 43fd562825 227/253: Merge pull request #36 from matiaslina/dont-highlight-operators-in-variables, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 5f885f4961 177/253: There's no need to install this, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode f6dcbaf9a4 190/253: Add raku exec path to customization group, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 3d43b91d82 209/253: Add syntax highlighting to REPL., ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode e0639c89a3 230/253: Merge pull request #35 from tmtvl/24-highlight-pod-the-same-as-comments, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 4ed7c06294 200/253: also detect '.rakutest' extension, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode b6a5535e27 219/253: Merge pull request #29 from tmtvl/auto-insert-skeletons, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 8a6e17f174 234/253: Merge pull request #41 from anquegi/master, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 6fa383e25f 003/253: More robust magic matching of Perl 6 code,
ELPA Syncer <=
- [nongnu] elpa/raku-mode ce3ef00b82 026/253: Syntax propertize <quoted words>, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 3cf62b8383 002/253: Only check if .t/.pl/.pm files contain Perl 6 code, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 1b0698744b 015/253: Move Perl 6 detection into perl6-detect.el, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 2f3b6f5eec 039/253: Remvoe superfluous space, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 1a7cb03101 050/253: Slight change in wording, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 4b8f5150d6 063/253: Break line in two, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 44c6e42d56 044/253: Highlight basic punctuation/match variables, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode eb32e01386 045/253: Correctly highilight version literal ranges, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode d2dfe7031c 073/253: Don't apply punctuation syntax to all set operators, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode e7e04422d0 052/253: Don't bug me with email notifications, ELPA Syncer, 2022/01/29