[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master fc8f4e7 01/27: Initial commit
From: |
Dmitry Gutov |
Subject: |
[elpa] master fc8f4e7 01/27: Initial commit |
Date: |
Sat, 29 Oct 2016 00:04:17 +0000 (UTC) |
branch: master
commit fc8f4e7429bcf3a961be8bc975c4173df2d87021
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>
Initial commit
---
highlight-escape-sequences.el | 89 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 89 insertions(+)
diff --git a/highlight-escape-sequences.el b/highlight-escape-sequences.el
new file mode 100644
index 0000000..fa1c3d5
--- /dev/null
+++ b/highlight-escape-sequences.el
@@ -0,0 +1,89 @@
+;;; highlight-escape-sequences.el --- Highlight escape sequences -*-
lexical-binding: t -*-
+
+;; Author: Dmitry Gutov <address@hidden>
+;; URL: https://github.com/dgutov/highlight-escape-sequences
+;; Keywords: convenience
+;; Version: 0.1
+
+;; This file is not part of GNU Emacs.
+
+;; This file 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 file 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This global minor mode highlights escape sequences in string
+;; literals with `font-lock-regexp-grouping-backslash' face when
+;; appropriate.
+
+;; It currently supports `ruby-mode' and both main JavaScript modes.
+
+;; To enable it in other modes, customize `hes-simple-modes'.
+
+;; Put this in the init file:
+;;
+;; (hes-mode)
+
+;;; Code:
+
+(defgroup hes-mode nil
+ "Highlight escape sequences"
+ :group 'convenience)
+
+(defconst hes-escape-sequence-re
+ "\\(\\\\\\(\\(?:[0-9]\\|x\\)\\(?:[0-9]\\(?:[0-9]\\)?\\)?\\|.\\)\\)"
+ "Regexp to match an escape sequence.
+Currently handles octals (\\123), hexadecimals (\\x12) and
+backslash followed by anything else.")
+
+(defconst hes-ruby-keywords
+ `((,hes-escape-sequence-re
+ (1 (let* ((state (syntax-ppss))
+ (term (nth 3 state)))
+ (when (or (and (eq term ?')
+ (member (match-string 2) '("\\" "'")))
+ (if (fboundp 'ruby-syntax-expansion-allowed-p)
+ (ruby-syntax-expansion-allowed-p state)
+ (memq term '(?\" ?/ ?\n t))))
+ 'font-lock-regexp-grouping-backslash))
+ prepend))))
+
+(defconst hes-simple-keywords
+ `((,hes-escape-sequence-re
+ (1 (when (nth 3 (syntax-ppss))
+ 'font-lock-regexp-grouping-backslash)
+ prepend))))
+
+(defcustom hes-simple-modes '(js-mode js2-mode)
+ "Modes where escape sequences can appear in any string literal."
+ :type '(repeat function)
+ :set (lambda (symbol value)
+ (hes-mode -1)
+ (set-default symbol value)
+ (hes-mode 1)))
+
+(define-minor-mode hes-mode
+ "Toggle highlighting of escape sequences."
+ :lighter "" :global t
+ (if hes-mode
+ (progn
+ (font-lock-add-keywords 'ruby-mode hes-ruby-keywords 'append)
+ (dolist (mode hes-simple-modes)
+ (font-lock-add-keywords mode hes-simple-keywords 'append)))
+ (font-lock-remove-keywords 'ruby-mode hes-ruby-keywords)
+ (dolist (mode hes-simple-modes)
+ (font-lock-remove-keywords mode hes-simple-keywords))))
+
+(provide 'highlight-escape-sequences)
+
+;;; highlight-escape-sequences.el ends here
- [elpa] master updated (2a0dbe5 -> 0e74c8c), Dmitry Gutov, 2016/10/28
- [elpa] master 7777860 03/27: Autoload the mode function, Dmitry Gutov, 2016/10/28
- [elpa] master 74340d0 02/27: hes-ruby-keywords, fallback predicate: Allow in backquoted literals, Dmitry Gutov, 2016/10/28
- [elpa] master 4425527 04/27: hes-simple-mode setter: Fix initialization; turn on when needed, Dmitry Gutov, 2016/10/28
- [elpa] master f7a0074 06/27: Wrong words on the screenshot, Dmitry Gutov, 2016/10/28
- [elpa] master 0df3e63 12/27: Remove explicit group, Dmitry Gutov, 2016/10/28
- [elpa] master 6bc14c4 16/27: Beautify hes-ruby-escape-sequence-keywords, Dmitry Gutov, 2016/10/28
- [elpa] master 828cdbb 08/27: Improve regexp and add two faces, Dmitry Gutov, 2016/10/28
- [elpa] master fc8f4e7 01/27: Initial commit,
Dmitry Gutov <=
- [elpa] master 8098664 05/27: Add readme and screenshot, Dmitry Gutov, 2016/10/28
- [elpa] master 5d45ca5 13/27: Fix the Author: header, Dmitry Gutov, 2016/10/28
- [elpa] master a031ee2 20/27: Add Emacs Lisp and Clojure (same as Java), Dmitry Gutov, 2016/10/28
- [elpa] master 083954e 19/27: Restore compatibility with earlier Emacsen, Dmitry Gutov, 2016/10/28
- [elpa] master 20d3190 22/27: Update copyright, Dmitry Gutov, 2016/10/28
- [elpa] master 02b8d09 10/27: Add more specific regexps, Dmitry Gutov, 2016/10/28
- [elpa] master 9c80a93 18/27: Merge pull request #1 from dev-plvlml/master, Dmitry Gutov, 2016/10/28
- [elpa] master 72c3cdc 07/27: Change wording, Dmitry Gutov, 2016/10/28
- [elpa] master 1e79174 11/27: Fix extra indent, Dmitry Gutov, 2016/10/28
- [elpa] master fa6dd96 24/27: Delete the obsolete alias, Dmitry Gutov, 2016/10/28