[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/raku-mode 6cb23a3a64 058/253: Move indentation support int
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/raku-mode 6cb23a3a64 058/253: Move indentation support into perl6-indent.el |
Date: |
Sat, 29 Jan 2022 08:28:42 -0500 (EST) |
branch: elpa/raku-mode
commit 6cb23a3a6444369da6830a75b4531102e94820a9
Author: Hinrik Örn Sigurðsson <hinrik.sig@gmail.com>
Commit: Hinrik Örn Sigurðsson <hinrik.sig@gmail.com>
Move indentation support into perl6-indent.el
---
Makefile | 2 +-
README.md | 6 +++--
perl6-indent.el | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
perl6-mode.el | 65 +++------------------------------------------------
4 files changed, 80 insertions(+), 65 deletions(-)
diff --git a/Makefile b/Makefile
index 07066008cf..bbfae9c377 100644
--- a/Makefile
+++ b/Makefile
@@ -7,7 +7,7 @@ export EMACS
PKGDIR := $(shell EMACS=$(EMACS) $(CASK) package-directory)
-SRCS = perl6-mode.el perl6-font-lock.el perl6-detect.el
+SRCS := $(wildcard *.el)
OBJS = $(SRCS:.el=.elc)
.PHONY: compile test clean
diff --git a/README.md b/README.md
index d8fef19df1..c0e4b05e90 100644
--- a/README.md
+++ b/README.md
@@ -10,11 +10,13 @@ This mode needs GNU Emacs 24.4.
## Features
-* Syntax highlighting (very much a work in progress)
+* Basic syntax highlighting
+* Basic indentation
#### Planned
-* Indentation
+* Complete syntax highlighting
+* Better indentation support
* Help system
* REPL interaction
* imenu support
diff --git a/perl6-indent.el b/perl6-indent.el
new file mode 100644
index 0000000000..b07acac279
--- /dev/null
+++ b/perl6-indent.el
@@ -0,0 +1,72 @@
+;;; perl6-indent.el --- Indentation support Perl 6 -*- lexical-binding: t; -*-
+
+;;; Commentary:
+
+;; SMIE grammar and various (auto-)indenting functions and variables are
+;; defined here. Currently it's mostly borrowed from css-mode.
+
+;;; Code:
+
+(require 'smie)
+
+(defconst perl6-smie-grammar
+ (smie-prec2->grammar
+ (smie-precs->prec2 '((assoc ";") (assoc ",") (left ":")))))
+
+(defcustom perl6-indent-offset 4
+ "Basic size of one indentation step."
+ :type 'integer
+ :group 'perl6)
+
+(defun perl6-smie--not-interpolation-p ()
+ (save-excursion
+ (forward-char -1)
+ (or (zerop (skip-chars-backward "-[:alnum:]"))
+ (not (looking-back "#{\\$" (- (point) 3))))))
+
+(defun perl6-smie--forward-token ()
+ (cond
+ ((and (eq (char-before) ?\})
+ (perl6-smie--not-interpolation-p)
+ ;; FIXME: If the next char is not whitespace, what should we do?
+ (or (memq (char-after) '(?\s ?\t ?\n))
+ (looking-at comment-start-skip)))
+ (if (memq (char-after) '(?\s ?\t ?\n))
+ (forward-char 1) (forward-comment 1))
+ ";")
+ ((progn (forward-comment (point-max))
+ (looking-at "[;,:]"))
+ (forward-char 1) (match-string 0))
+ (t (smie-default-forward-token))))
+
+(defun perl6-smie--backward-token ()
+ (let ((pos (point)))
+ (forward-comment (- (point)))
+ (cond
+ ;; FIXME: If the next char is not whitespace, what should we do?
+ ((and (eq (char-before) ?\}) (perl6-smie--not-interpolation-p)
+ (> pos (point))) ";")
+ ((memq (char-before) '(?\; ?\, ?\:))
+ (forward-char -1) (string (char-after)))
+ (t (smie-default-backward-token)))))
+
+(defun perl6-smie-rules (kind token)
+ (pcase (cons kind token)
+ (`(:elem . basic) perl6-indent-offset)
+ (`(:elem . arg) 0)
+ (`(:list-intro . ,(or `";" `"")) t) ;"" stands for BOB (bug#15467).
+ (`(:before . "{")
+ (when (smie-rule-hanging-p)
+ (smie-backward-sexp ";")
+ (smie-indent-virtual)))
+ (`(:before . ,(or "{" "("))
+ (if (smie-rule-hanging-p) (smie-rule-parent 0)))))
+
+(provide 'perl6-indent)
+
+;; Local Variables:
+;; coding: utf-8
+;; indent-tabs-mode: nil
+;; End:
+
+;;; perl6-indent.el ends here
diff --git a/perl6-mode.el b/perl6-mode.el
index 825657443c..43ba2f4266 100644
--- a/perl6-mode.el
+++ b/perl6-mode.el
@@ -40,65 +40,7 @@
(require 'perl6-detect)
(require 'perl6-font-lock)
-
-
-(require 'smie)
-
-(defconst perl6-smie-grammar
- (smie-prec2->grammar
- (smie-precs->prec2 '((assoc ";") (assoc ",") (left ":")))))
-
-(defun perl6-smie--not-interpolation-p ()
- (save-excursion
- (forward-char -1)
- (or (zerop (skip-chars-backward "-[:alnum:]"))
- (not (looking-back "#{\\$" (- (point) 3))))))
-
-
-
-(defun perl6-smie--forward-token ()
- (cond
- ((and (eq (char-before) ?\})
- (perl6-smie--not-interpolation-p)
- ;; FIXME: If the next char is not whitespace, what should we do?
- (or (memq (char-after) '(?\s ?\t ?\n))
- (looking-at comment-start-skip)))
- (if (memq (char-after) '(?\s ?\t ?\n))
- (forward-char 1) (forward-comment 1))
- ";")
- ((progn (forward-comment (point-max))
- (looking-at "[;,:]"))
- (forward-char 1) (match-string 0))
- (t (smie-default-forward-token))))
-
-(defun perl6-smie--backward-token ()
- (let ((pos (point)))
- (forward-comment (- (point)))
- (cond
- ;; FIXME: If the next char is not whitespace, what should we do?
- ((and (eq (char-before) ?\}) (perl6-smie--not-interpolation-p)
- (> pos (point))) ";")
- ((memq (char-before) '(?\; ?\, ?\:))
- (forward-char -1) (string (char-after)))
- (t (smie-default-backward-token)))))
-
-(defun perl6-smie-rules (kind token)
- (pcase (cons kind token)
- (`(:elem . basic) perl6-indent-offset)
- (`(:elem . arg) 0)
- (`(:list-intro . ,(or `";" `"")) t) ;"" stands for BOB (bug#15467).
- (`(:before . "{")
- (when (smie-rule-hanging-p)
- (smie-backward-sexp ";")
- (smie-indent-virtual)))
- (`(:before . ,(or "{" "("))
- (if (smie-rule-hanging-p) (smie-rule-parent 0)))))
-
-(defcustom perl6-indent-offset 4
- "Basic size of one indentation step."
- :version "22.2"
- :type 'integer)
-
+(require 'perl6-indent)
;;;###autoload
(define-derived-mode perl6-mode prog-mode "Perl6"
@@ -113,11 +55,10 @@
(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)
-
- )
+ :backward-token #'perl6-smie--backward-token))
(provide 'perl6-mode)
- [nongnu] elpa/raku-mode 623b5b559a 018/253: Syntaxify double colons around identifiers as symbol chars, (continued)
- [nongnu] elpa/raku-mode 623b5b559a 018/253: Syntaxify double colons around identifiers as symbol chars, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 142ff3e928 030/253: Highlight variable package differently from variable name, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 127b125ab1 034/253: Use a smaller heading, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 75e4c4831d 022/253: Clean up the code for comment detection a bit, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 0d3485a324 027/253: Better highlighting angled quotes, and set operators, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 7078ed08b4 033/253: font-lock-exit-face is not standard, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode f9bf3f7689 037/253: Improve code layout a bit, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 6a4269e30b 005/253: Make sure the magic autoloads correctly, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 0be377dba8 040/253: Place manual installation instructions last, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 8f9d68dc38 047/253: Add note about find-file-at-point, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 6cb23a3a64 058/253: Move indentation support into perl6-indent.el,
ELPA Syncer <=
- [nongnu] elpa/raku-mode 4917b2c270 055/253: Highlight #=() and #|() comments, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 284a341125 046/253: Set comment-start-skip, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode eaf48dd813 049/253: Add Travis integration, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode cf9d523c88 059/253: Use sharp quote (#') to quote function names, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode e3bcb55be3 077/253: Highlight adverbs (:foo), ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 95f6ca837c 078/253: Highlight sigil in match group ($<foo>), ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode c1b2f9e112 109/253: Less aggressive syntaxification of sigils/twigils, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 6553c30843 093/253: Highlight ::?CLASS and such correctly, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 861a7b469b 110/253: Highlight string delimiters like operators, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 5f66f10dbe 143/253: Correctly highlight $foo.?method, ELPA Syncer, 2022/01/29