diff options
Diffstat (limited to 'emacs/.emacs.d/site-lisp')
-rw-r--r-- | emacs/.emacs.d/site-lisp/n3-mode.el | 44 | ||||
-rw-r--r-- | emacs/.emacs.d/site-lisp/ppindent.el | 138 | ||||
-rw-r--r-- | emacs/.emacs.d/site-lisp/ttl-mode.el | 209 |
3 files changed, 391 insertions, 0 deletions
diff --git a/emacs/.emacs.d/site-lisp/n3-mode.el b/emacs/.emacs.d/site-lisp/n3-mode.el new file mode 100644 index 0000000..8beced6 --- /dev/null +++ b/emacs/.emacs.d/site-lisp/n3-mode.el @@ -0,0 +1,44 @@ +;;; n3-mode.el --- mode for Notation 3 +; $Id: n3-mode.el 4084 2007-12-15 17:10:13Z hugoh $ + +;; Copyright (c) 2003-2007 Hugo Haas <hugo@larve.net> + +;; For documentation on Notation 3, see: +;; http://www.w3.org/DesignIssues/Notation3.html + +;;; Comentary: + +;; Goals: +;; - sytax highlighting +;; - completion +;; - indentation + +;; What it does now: +;; - Syntax highlighting + +;;; Code: + +(require 'generic) + +(define-generic-mode 'n3-mode + ;; comment char + (list "# ") + ;; keywords + (list "this" "a") + ;; additional font-lock'ing + '(("\\(@prefix\\)\\>" 1 font-lock-keyword-face t) + ("\\(\\S-*?:\\)" 1 font-lock-type-face t) + (":\\(\\S-+?\\)\\>" 1 font-lock-constant-face t) + ("\\(<.*?>\\)" 1 font-lock-function-name-face t) + ("\\(\\\".*?\\\"\\)" 1 font-lock-string-face t) +; Bug: some trailing characters are highlighted; restricting comments regexp +; ("\\(#.*\\)" 1 font-lock-comment-face t) + ("^\\s-*\\(#.*\\)" 1 font-lock-comment-face t) + ) + ;; auto-mode + (list "\\.n3$") + ;; additional setup + nil + ;; description + "Mode for Notation 3 documents." + ) diff --git a/emacs/.emacs.d/site-lisp/ppindent.el b/emacs/.emacs.d/site-lisp/ppindent.el new file mode 100644 index 0000000..84c9702 --- /dev/null +++ b/emacs/.emacs.d/site-lisp/ppindent.el @@ -0,0 +1,138 @@ +;;; ppindent.el --- Indents C preprocessor directives + +;; Copyright (C) 2007 Free Software Foundation, Inc. + +;; Author: Craig McDaniel <craigmcd@gmail.com> +;; Keywords: languages, c +;; Maintainer: Craig McDaniel <craigmcd@gmail.com> + +;; 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 2, 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; see the file COPYING. If not, write to +;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +;; Boston, MA 02111-1307, USA. + +;;; Commentary: + +;; PPINDENT indents C-preprocessor statements depending on the current +;; #if..., #el.., #endif level. It only modifies lines with "#" as the +;; first non-blank character and therefore does not conflict with the +;; normal C indentation. Unlike a true indent, it inserts the +;; requisite number of spaces after, rather than before the "#" +;; character. This type of preprocesor indent is commonly used to +;; provide the most compatibility with different C-compilers. +;; +;; Example: + +;; #ifdef WOO +;; .... +;; #if defined(X) && !defined(Y) +;; #ifdef Q8 +;; ... +;; #else +;; ... +;; .... +;; #elif defined (Z) +;; .... +;; #endif +;; #endif +;; #endif + +;; After "M-x ppindent-c" becomes: + +;; #ifdef WOO +;; .... +;; # if defined(X) && !defined(Y) +;; # ifdef Q8 +;; ... +;; # else +;; ... +;; .... +;; # elif defined (Z) +;; .... +;; # endif +;; # endif +;; #endif + +;; Two functions are provided: PPINDENT-C indents as described +;; above. PPINDENT-H does not indent the first level, assuming that +;; .h/.hpp files use an #ifdef guard around the entire file. + +;; You can customize PPINDENT-INCREMENT if you want to use something +;; other than 2 spaces for the indent. + +;;; History: + +;; 2007-01-19 WCM Initial version + +;;; Code: + +(provide 'ppindent) + +(defgroup pp-indent nil + "Indent C preproccessor directives." + :group 'c) + +(defcustom ppindent-increment 2 + "Number of spaces per indention level. + +Used in C pre-processor indent functions ppindent-c and ppindent-h" + :type 'number + :group 'pp-indent) + +(defun starts-withp (str prefix) + "str starts with prefix" + (eql (compare-strings prefix nil nil str nil (length prefix)) t)) + +(defun my-make-string (length init) + "just like make-string, but makes an empty string if length is negative" + (when (minusp length) + (setf length 0)) + (make-string length init)) + +(defun ppindent-aux (start) + (let ((cnt start)) + (goto-char (point-min)) + (while (re-search-forward "^[ \t]*#[ \t]*\\(.*\\)" nil t) + (cond ((starts-withp (match-string-no-properties 1) "if") + (replace-match (concat "#" (my-make-string cnt ?\s) "\\1")) + (incf cnt ppindent-increment)) + ((starts-withp (match-string-no-properties 1) "el") + (when (< (- cnt ppindent-increment) start) + (throw 'err `(,(line-number-at-pos) "Unmatched #else or #elif"))) + (replace-match (concat "#" (my-make-string + (- cnt ppindent-increment) + ?\s) "\\1"))) + ((starts-withp (match-string-no-properties 1) "endif") + (when (< (- cnt ppindent-increment) start) + (throw 'err `(,(line-number-at-pos) "Unmatched #endif"))) + (decf cnt ppindent-increment) + (replace-match (concat "#" (my-make-string cnt ?\s) "\\1"))) + (t + (replace-match (concat "#" (my-make-string cnt ?\s) "\\1"))))))) + +(defun ppindent-buffer (start) + (let ((result (catch 'err (save-excursion (ppindent-aux start))))) + (when result + (goto-line (car result)) + (error "Error: %s" (cadr result))))) + +(defun ppindent-c () + "Indent all C pre-processor statements" + (interactive) + (ppindent-buffer 0)) + +(defun ppindent-h () + "Indent C pre-processor statements, keeping first level #ifdef unindented" + (interactive) + (ppindent-buffer (- ppindent-increment))) + diff --git a/emacs/.emacs.d/site-lisp/ttl-mode.el b/emacs/.emacs.d/site-lisp/ttl-mode.el new file mode 100644 index 0000000..ee147de --- /dev/null +++ b/emacs/.emacs.d/site-lisp/ttl-mode.el @@ -0,0 +1,209 @@ +;;; ttl-mode.el --- mode for Turtle(RDF) +;; Based on n3-mode.el --- mode for Notation 3, +;; at http://larve.net/people/hugo/2003/scratchpad/NotationThreeEmacsMode.html +;; Also draws on http://dishevelled.net/elisp/turtle-mode.el (which is for the _other_ turtle!) + +;; Copyright (c) 2003-2007 Hugo Haas <hugo@larve.net> +;; Extended 2011-2012, by Norman Gray <http://nxg.me.uk> +;; +;; See Hugo's commentary for original goals and further discussion. + +;; Project hosted at <https://bitbucket.org/nxg/ttl-mode>. See there for updates. + +;; To use: +;; +;; (autoload 'ttl-mode "ttl-mode" "Major mode for OWL or Turtle files" t) +;; (add-hook 'ttl-mode-hook ; Turn on font lock when in ttl mode +;; 'turn-on-font-lock) +;; (setq auto-mode-alist +;; (append +;; (list +;; '("\\.n3" . ttl-mode) +;; '("\\.ttl" . ttl-mode)) +;; auto-mode-alist)) + +;;; Code: + +(require 'generic) + +(define-generic-mode 'ttl + ;; comment char + (list "# ") + ;; keywords + (list "this" "a") + ;; additional font-lock'ing + '(("\\(@prefix\\)\\>" 1 font-lock-keyword-face t) ;keywords + ("\\^\\^[^,;.]+" 0 font-lock-preprocessor-face t) ;literal types + ("@[[:word:]_]+" 0 font-lock-preprocessor-face t) ;languages + ("\\(\\S-*?:\\)" 1 font-lock-type-face nil) ;prefix + (":\\([[:word:]_-]+\\)\\>" 1 font-lock-constant-face nil) ;suffix + ("\\(<.*?>\\)" 1 font-lock-function-name-face t) ;resources + ("\\(\\\".*?\\\"\\)" 1 font-lock-string-face t) ;strings + ("\\(\\\"\\\"\\\".*?\\\"\\\"\\\"\\)" 1 font-lock-string-face t) ;doesn't work over newlines? +; Bug: some trailing characters are highlighted; restricting comments regexp +; ("\\(#.*\\)" 1 font-lock-comment-face t) + ("^\\s-*\\(#.*\\)" 1 font-lock-comment-face t) ;comment + ) + ;; auto-mode + (list "\\.n3$" "\\.ttl") + ;; additional setup + nil + ;; description + "Mode for Turtle RDF documents." + ) + +(defun ttl-base () + (interactive) + (generic-mode "ttl")) + +(defun ttl-indent-line () + (interactive) + (indent-line-to + (or (ignore-errors (ttl-calculate-indentation)) + 0))) + +(defun ttl-calculate-indentation () + (save-excursion + (beginning-of-line) (skip-chars-forward "\t ") + (cond ((ttl-in-string-p) 8) + ((looking-at "$") + ;; empty line -- use same indentation as previous line + (save-excursion + (forward-line -1) + (skip-chars-forward "\t ") + (current-column))) + ((looking-at "@") 0) ;@prefix or @base + ((looking-at "#") 0) + ((looking-at "<");(looking-at "\\S-+\\s-*$") + ;;only a single expression on the line -- a subject + 0) + ((save-excursion + (forward-line -1) + (end-of-line) + (if (not (looking-back "\\[")) + nil + (beginning-of-line) + (skip-chars-forward "\t ") + (+ (current-column) 4)))) + (t 4)))) + +;; (defun turtle-indent-block () +;; (interactive) +;; (indent-region (point) +;; (save-excursion (forward-xxx) (point)))) + +(defvar ttl-mode-map (make-sparse-keymap)) +(define-derived-mode ttl-mode ttl-base + "Turtle RDF" + (setq indent-tabs-mode t) + (ttl-mode-variables) +; (define-key ttl-mode-map (kbd "C-M-q") +; 'turtle-indent-block) + (define-key ttl-mode-map (kbd "\;") 'ttl-electric-semi) + (define-key ttl-mode-map (kbd "\.") 'ttl-electric-dot) + (define-key ttl-mode-map (kbd "RET") 'newline-and-indent) + (define-key ttl-mode-map [backspace] 'ttl-hungry-delete-backwards) + (use-local-map ttl-mode-map)) + +(defcustom ttl-electric-semi-mode nil + "*If non-nil, `\;' will self insert, reindent the line, and do a newline. +If nil, just insert a `\;'. (To insert while t, do: \\[quoted-insert] \;)." + :group 'ttl + :type 'boolean) + +(defun beginning-of-stanza () + "Find the beginning of a stanza, indicated by non-whitespace at the beginning of a line." + (re-search-backward "^\\S-" (point-min) t)) + +(defun ttl-in-string-p () + "Is point inside a string or a long-string?" + (save-excursion + (let ((here (point)) + (in-p nil)) + (beginning-of-stanza) + (condition-case nil + (progn + (while (<= (point) here) + (if in-p + (progn + (search-forward in-p (point-max) nil) + (setq in-p nil)) + (re-search-forward "\"\\(\"\"\\)?" (point-max) nil) + (if (char-equal (char-before (- (point) 1)) ?\") + (setq in-p "\"\"\"") + (setq in-p "\"")))) + (not in-p)) + (search-failed ;reached EOF + (if in-p ;this indicates that we're inside a string + (message "Unbalanced quotes -- reached EOF inside string") + nil)))))) + +(defun *ttl-search-in-line-for-comment (limit) + "Search for a comment character from the current position, before point LIMIT; changes current position. Return location of comment, or nil if none can be found" + (let ((new-point (re-search-forward "[#<]" limit t))) + (cond ((not new-point) nil) + ((looking-back "#") new-point) ;found comment + (t ;looking-back "<" + (if (not (search-forward ">" limit t)) + nil ;starting point is within resource + (*ttl-search-in-line-for-comment limit)))))) ;recurse + +(defun ttl-in-comment-p () + "Is point inside a comment?" + (save-excursion + (let ((here (point))) + (beginning-of-line) + (*ttl-search-in-line-for-comment here)))) + +(defun ttl-in-resource-p () + "Is point within a resource, marked by <...>?" + (save-excursion + (and (re-search-backward "[<> ]" nil t) + (looking-at "<")))) + +(defun ttl-skip-ws-backwards () ;adapted from cc-mode + "Move backwards across whitespace." + (while (progn + (skip-chars-backward " \t\n\r\f\v") + (and (eolp) + (eq (char-before) ?\\))) + (backward-char))) + +(defun ttl-hungry-delete-backwards () + "Delete backwards, either all of the preceding whitespace, +or a single non-whitespace character if there is no whitespace before point." + (interactive) + (let ((here (point))) + (ttl-skip-ws-backwards) + (if (/= (point) here) + (delete-region (point) here) + (backward-delete-char-untabify 1)))) + +(defun ttl-insulate () + "Return true if this location should not be electrified" + (or (ttl-in-string-p) + (ttl-in-comment-p) + (ttl-in-resource-p))) + +(defun ttl-electric-semi () + "Insert a \;. +If variable `ttl-electric-semi-mode' is t, indent the current line, insert +a newline, and indent." + (interactive) + (insert "\;") + (if (and ttl-electric-semi-mode + (not (ttl-insulate))) + (reindent-then-newline-and-indent))) + +(defun ttl-electric-dot () + "Insert a \.. +If variable `ttl-electric-semi-mode' is t, indent the current line, insert +a newline, and indent." + (interactive) + (insert "\.") + (if (and ttl-electric-semi-mode + (not (ttl-insulate))) + (reindent-then-newline-and-indent))) + +(defun ttl-mode-variables () + (set (make-local-variable 'indent-line-function) 'ttl-indent-line)) |