From a6a2922c75fa06fb2496d2ba59520a121205fd26 Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Thu, 3 Mar 2016 10:45:20 +0100 Subject: Handle .ino files with c++-mode. Upgrade yasnippet and yaml. --- .emacs.d/lisp/yaml-mode.el | 117 +++++++++++++++++++-------------------------- .emacs.d/lisp/yasnippet.el | 6 +-- 2 files changed, 52 insertions(+), 71 deletions(-) (limited to '.emacs.d') diff --git a/.emacs.d/lisp/yaml-mode.el b/.emacs.d/lisp/yaml-mode.el index b932576..39c0e57 100644 --- a/.emacs.d/lisp/yaml-mode.el +++ b/.emacs.d/lisp/yaml-mode.el @@ -183,35 +183,33 @@ that key is pressed to begin a block literal." ;; Mode setup -(defvar yaml-mode-map () +(defvar yaml-mode-map + (let ((map (make-sparse-keymap))) + (define-key map "|" 'yaml-electric-bar-and-angle) + (define-key map ">" 'yaml-electric-bar-and-angle) + (define-key map "-" 'yaml-electric-dash-and-dot) + (define-key map "." 'yaml-electric-dash-and-dot) + (define-key map [backspace] 'yaml-electric-backspace) + map) "Keymap used in `yaml-mode' buffers.") -(if yaml-mode-map - nil - (setq yaml-mode-map (make-sparse-keymap)) - (define-key yaml-mode-map "|" 'yaml-electric-bar-and-angle) - (define-key yaml-mode-map ">" 'yaml-electric-bar-and-angle) - (define-key yaml-mode-map "-" 'yaml-electric-dash-and-dot) - (define-key yaml-mode-map "." 'yaml-electric-dash-and-dot) - (define-key yaml-mode-map [backspace] 'yaml-electric-backspace)) - -(defvar yaml-mode-syntax-table nil + +(defvar yaml-mode-syntax-table + (let ((syntax-table (make-syntax-table))) + (modify-syntax-entry ?\' "\"" syntax-table) + (modify-syntax-entry ?\" "\"" syntax-table) + (modify-syntax-entry ?# "<" syntax-table) + (modify-syntax-entry ?\n ">" syntax-table) + (modify-syntax-entry ?\\ "\\" syntax-table) + (modify-syntax-entry ?- "w" syntax-table) + (modify-syntax-entry ?_ "_" syntax-table) + (modify-syntax-entry ?\( "." syntax-table) + (modify-syntax-entry ?\) "." syntax-table) + (modify-syntax-entry ?\{ "(}" syntax-table) + (modify-syntax-entry ?\} "){" syntax-table) + (modify-syntax-entry ?\[ "(]" syntax-table) + (modify-syntax-entry ?\] ")[" syntax-table) + syntax-table) "Syntax table in use in `yaml-mode' buffers.") -(if yaml-mode-syntax-table - nil - (setq yaml-mode-syntax-table (make-syntax-table)) - (modify-syntax-entry ?\' "\"" yaml-mode-syntax-table) - (modify-syntax-entry ?\" "\"" yaml-mode-syntax-table) - (modify-syntax-entry ?# "<" yaml-mode-syntax-table) - (modify-syntax-entry ?\n ">" yaml-mode-syntax-table) - (modify-syntax-entry ?\\ "\\" yaml-mode-syntax-table) - (modify-syntax-entry ?- "w" yaml-mode-syntax-table) - (modify-syntax-entry ?_ "_" yaml-mode-syntax-table) - (modify-syntax-entry ?\( "." yaml-mode-syntax-table) - (modify-syntax-entry ?\) "." yaml-mode-syntax-table) - (modify-syntax-entry ?\{ "(}" yaml-mode-syntax-table) - (modify-syntax-entry ?\} "){" yaml-mode-syntax-table) - (modify-syntax-entry ?\[ "(]" yaml-mode-syntax-table) - (modify-syntax-entry ?\] ")[" yaml-mode-syntax-table)) ;;;###autoload (define-derived-mode yaml-mode text-mode "YAML" @@ -224,34 +222,37 @@ that key is pressed to begin a block literal." (set (make-local-variable 'indent-line-function) 'yaml-indent-line) (set (make-local-variable 'indent-tabs-mode) nil) (set (make-local-variable 'fill-paragraph-function) 'yaml-fill-paragraph) - (set (make-local-variable 'font-lock-defaults) - '(yaml-font-lock-keywords - nil nil nil nil - (font-lock-syntactic-keywords . yaml-font-lock-syntactic-keywords))) - (if (fboundp 'font-lock-flush) - (font-lock-flush) - (with-no-warnings - (font-lock-fontify-buffer)))) + + (set (make-local-variable 'syntax-propertize-function) + 'yaml-mode-syntax-propertize-function) + (setq font-lock-defaults '(yaml-font-lock-keywords))) ;; Font-lock support (defvar yaml-font-lock-keywords - (list - (cons yaml-constant-scalars-re '(1 font-lock-constant-face)) - (cons yaml-tag-re '(0 font-lock-type-face)) - (cons yaml-node-anchor-alias-re '(0 font-lock-function-name-face)) - (cons yaml-hash-key-re '(1 font-lock-variable-name-face)) - (cons yaml-document-delimiter-re '(0 font-lock-comment-face)) - (cons yaml-directive-re '(1 font-lock-builtin-face)) - '(yaml-font-lock-block-literals 0 font-lock-string-face) - '("^[\t]+" 0 'yaml-tab-face t)) + `((,yaml-constant-scalars-re . (1 font-lock-constant-face)) + (,yaml-tag-re . (0 font-lock-type-face)) + (,yaml-node-anchor-alias-re . (0 font-lock-function-name-face)) + (,yaml-hash-key-re . (1 font-lock-variable-name-face)) + (,yaml-document-delimiter-re . (0 font-lock-comment-face)) + (,yaml-directive-re . (1 font-lock-builtin-face)) + (yaml-font-lock-block-literals 0 font-lock-string-face) + ("^[\t]+" 0 'yaml-tab-face t)) "Additional expressions to highlight in YAML mode.") -(defvar yaml-font-lock-syntactic-keywords - (list '(yaml-syntactic-block-literals 0 ".")) - "Additional syntax features to highlight in YAML mode.") - +(defun yaml-mode-syntax-propertize-function (beg end) + "Unhighlight foo#bar tokens between BEG and END." + (save-excursion + (goto-char beg) + (while (search-forward "#" end t) + (save-excursion + (forward-char -1) + ;; both ^# and [ \t]# are comments + (when (and (not (bolp)) + (not (memq (preceding-char) '(?\s ?\t)))) + (put-text-property (point) (1+ (point)) + 'syntax-table (string-to-syntax "_"))))))) (defun yaml-font-lock-block-literals (bound) "Find lines within block literals. @@ -292,26 +293,6 @@ artificially limitted to the value of bound t)) (set-match-data (nthcdr 2 (match-data))) t)))))) -(defun yaml-syntactic-block-literals (bound) - "Find quote characters within block literals. -Finds the first quote character within a block literal (if any) after -point and prior to BOUND. Returns the position of the quote character -in the match data, as consumed by matcher functions in -`font-lock-syntactic-keywords'. This allows the mode to treat ['\"] -characters in block literals as punctuation syntax instead of string -syntax, preventing unmatched quotes in block literals from painting -the entire buffer in `font-lock-string-face'." - (let ((found nil)) - (while (and (not found) - (/= (point) bound) - (yaml-font-lock-block-literals bound)) - (let ((begin (match-beginning 0)) (end (match-end 0))) - (goto-char begin) - (cond - ((re-search-forward "['\"]" end t) (setq found t)) - ((goto-char end))))) - found)) - ;; Indentation and electric keys diff --git a/.emacs.d/lisp/yasnippet.el b/.emacs.d/lisp/yasnippet.el index 69d6b26..b68389f 100644 --- a/.emacs.d/lisp/yasnippet.el +++ b/.emacs.d/lisp/yasnippet.el @@ -3390,9 +3390,9 @@ BEG, END and LENGTH like overlay modification hooks." (= (point) (yas--field-start field)) (require 'delsel) ;; `yank' sets `this-command' to t during execution. - (let ((clearp (get (if (commandp this-command) this-command - this-original-command) - 'delete-selection))) + (let* ((command (if (commandp this-command) this-command + this-original-command)) + (clearp (if (symbolp command) (get command 'delete-selection)))) (when (and (not (memq clearp '(yank supersede kill))) (functionp clearp)) (setq clearp (funcall clearp))) -- cgit v1.3