Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

julia-mode.el: Highlight triple-quoted strings and characters. #9152

Merged
merged 5 commits into from
Nov 30, 2014
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fontify strings and chars as strings, not keywords.
This is faster and less code.
  • Loading branch information
Wilfred committed Nov 25, 2014
commit 9b2934083d1815b3b3129a7be942264b5a9b7a02
53 changes: 18 additions & 35 deletions contrib/julia-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,13 @@ This function provides equivalent functionality, but makes no efforts to optimis
(modify-syntax-entry ?\] ")[ " table)
(modify-syntax-entry ?\( "() " table)
(modify-syntax-entry ?\) ")( " table)
;(modify-syntax-entry ?\\ "." table) ; \ is an operator outside quotes
(modify-syntax-entry ?' "." table) ; character quote or transpose
;; Here, we treat ' as punctuation (when it's used for transpose),
;; see our use of `julia-char-regex' for handling ' as a character
;; delimeter
(modify-syntax-entry ?' "." table)
(modify-syntax-entry ?\" "\"" table)
(modify-syntax-entry ?` "\"" table)
;; (modify-syntax-entry ?\" "." table)

(modify-syntax-entry ?. "." table)
(modify-syntax-entry ?? "." table)
(modify-syntax-entry ?$ "." table)
Expand All @@ -95,31 +97,16 @@ This function provides equivalent functionality, but makes no efforts to optimis
table)
"Syntax table for `julia-mode'.")

;; syntax table that holds within strings
(defvar julia-mode-string-syntax-table
(let ((table (make-syntax-table)))
table)
"Syntax table for `julia-mode'.")

;; disable " inside char quote
(defvar julia-mode-char-syntax-table
(let ((table (make-syntax-table)))
(modify-syntax-entry ?\" "." table)
table)
"Syntax table for `julia-mode'.")

(defconst julia-string-regex
"\"[^\"]*?\\(\\(\\\\\\\\\\)*\\\\\"[^\"]*?\\)*\"")

(defconst julia-char-regex
(rx (submatch (or (any "-" ";" "\\" "^" "!" "|" "?" "*" "<" "%" "," "=" ">" "+" "/" "&" "$" "~" ":")
(syntax open-parenthesis)
(syntax whitespace)
bol))
(submatch "'"
(or (repeat 0 8 (not (any "'"))) (not (any "\\"))
"\\\\")
"'")))
(rx (or (any "-" ";" "\\" "^" "!" "|" "?" "*" "<" "%" "," "=" ">" "+" "/" "&" "$" "~" ":")
(syntax open-parenthesis)
(syntax whitespace)
bol)
(group "'")
(group
(or (repeat 0 8 (not (any "'"))) (not (any "\\"))
"\\\\"))
(group "'")))

(defconst julia-unquote-regex
"\\(\\s(\\|\\s-\\|-\\|[,%=<>\\+*/?&|!\\^~\\\\;:]\\|^\\)\\($[a-zA-Z0-9_]+\\)")
Expand Down Expand Up @@ -202,7 +189,6 @@ This function provides equivalent functionality, but makes no efforts to optimis
'symbols)
'font-lock-constant-face)
(list julia-unquote-regex 2 'font-lock-constant-face)
(list julia-char-regex 2 'font-lock-string-face)
(list julia-forloop-in-regex 1 'font-lock-keyword-face)
(list julia-function-regex 1 'font-lock-function-name-face)
(list julia-function-assignment-regex 1 'font-lock-function-name-face)
Expand Down Expand Up @@ -399,13 +385,10 @@ before point. Returns nil if we're not within nested parens."
(set (make-local-variable 'font-lock-defaults) '(julia-font-lock-keywords))
(set (make-local-variable 'font-lock-syntactic-keywords)
(list
(list "\\(\\\\\\)\\s-*\".*?\"" 1 julia-mode-char-syntax-table)))
(set (make-local-variable 'font-lock-syntactic-keywords)
(list
(list julia-char-regex 2
julia-mode-char-syntax-table)
(list julia-string-regex 0
julia-mode-string-syntax-table)
`(,julia-char-regex
(1 "\"") ; Treat ' as a string delimiter.
(2 ".") ; Don't highlight anything between the open and close '.
(3 "\"")) ; Treat the close ' as a string delimiter.
))
(set (make-local-variable 'indent-line-function) 'julia-indent-line)
(set (make-local-variable 'julia-basic-offset) 4)
Expand Down