161 lines
5.1 KiB

(defgroup agw nil
"Alison G. Watson's customizations."
:prefix "agw-"
:group 'convenience)
(defvar agw-mode-map (make-sparse-keymap)
"Global keymap for `agw-mode'.")
(defvar-local agw-no-fixes nil
"Fixes files before save if nil in this buffer.")
(defvar-local agw-no-tabs nil
"Disables tabs in this buffer.")
(defvar-local agw-no-tabs-width 2
"The width of non-hardware tabs with `agw-no-tabs'.")
(defvar-local agw-work nil
"Changes functionality for a work environment.")
(define-minor-mode agw-key-map-mode
"Minor mode for key bindings."
:global t
:keymap agw-mode-map)
(defun agw-set-key (key def)
"Binds a key into `agw-mode-map'."
(define-key agw-mode-map (kbd (concat "C-<tab> " key)) def))
(defun agw-fp-mode ()
"Sets up lisp and other functional language major modes."
(setq-local agw-no-tabs t))
(defun agw-org-mode ()
"Sets up `org-mode'."
(setq-local agw-no-tabs t)
(define-key evil-normal-state-map (kbd "TAB") 'org-cycle))
(defun agw-cc-mode ()
"Sets up `c-mode' and `c++-mode'."
(c-toggle-electric-state -1))
(defun agw-before-save ()
"Hook to be run before saving a file."
(unless agw-no-fixes
(defun agw-remove-elc ()
"Removes an elc file if it exists."
(let ((elc (concat buffer-file-name "c")))
(if (file-exists-p elc)
(delete-file elc))))
(defun agw-el-mode ()
"Sets up `emacs-lisp-mode'."
(add-hook 'after-save-hook #'agw-remove-elc nil t))
(defun agw-evil-visual-state-tag (&optional selection)
"Displays the mode for the visual state."
(let ((selection (or selection evil-visual-selection)))
(cond ((eq selection 'char) "v")
((eq selection 'line) "V")
((eq selection 'screen-line) "ʌ")
((eq selection 'block) "Λ"))))
(defun agw-prog-mode ()
"Sets up `prog-mode' and `text-mode'."
(setq-local tab-always-indent t)
(when agw-work
(setq-local agw-no-tabs t
agw-no-tabs-width 4))
(if agw-no-tabs
(setq-local indent-tabs-mode nil
standard-indent agw-no-tabs-width
tab-width agw-no-tabs-width)
(smart-tabs-mode 0))
(setq-local indent-tabs-mode t
standard-indent 3
tab-width 3)
(smart-tabs-mode 1))))
(defun agw-after-local-vars ()
(if (or (derived-mode-p 'prog-mode) (derived-mode-p 'text-mode))
;; Lithium dialogues mode
(setq agw-lithdlg-highlights
(let* (( keywords '("dialogue" "terminal" "program" "page" "failure"
"finished" "unfinished" "if" "else"))
(functions '("option" "page" "name" "icon" "remote"
"teleport_interlevel" "teleport_intralevel"
"script" "logon" "logoff" "pict" "info" "text"))
( keyword-regexp (regexp-opt keywords 'words))
(function-regexp (regexp-opt functions 'words)))
`(( ,keyword-regexp . font-lock-keyword-face)
(,function-regexp . font-lock-function-name-face))))
(setq agw-lithdlg-syntax
(let ((table (make-syntax-table)))
(modify-syntax-entry ?/ ". 14n" table)
(modify-syntax-entry ?* ". 23n" table)
(define-derived-mode agw-lithdlg-mode prog-mode "lithdlg"
"Major mode for Lithium dialogues."
(setq font-lock-defaults '(agw-lithdlg-highlights))
(set-syntax-table agw-lithdlg-syntax))
(provide 'agw-lithdlg-mode)
;; Lithium sound definition mode
(setq agw-lithsnd-highlights '(("\\$[a-z]+\\|==" . font-lock-keyword-face)))
(setq agw-lithsnd-syntax
(let ((table (make-syntax-table)))
(modify-syntax-entry ?# "<" table)
(modify-syntax-entry ?\n ">" table)
(define-derived-mode agw-lithsnd-mode prog-mode "lithsnd"
"Major mode for Lithium sound definitions."
(setq font-lock-defaults '(agw-lithsnd-highlights))
(set-syntax-table agw-lithsnd-syntax))
(provide 'agw-lithsnd-mode)
;; Lithium text definition mode
(setq agw-lithtxt-highlights
'(("^\\(\\(==\\|%%\\|@@\\|\\+\\+\\|!![a-z]+\\) \\|@@$\\)" .
("^##.*$" . font-lock-comment-face)
("\\\\#" . font-lock-constant-face)))
(define-derived-mode agw-lithtxt-mode prog-mode "lithtxt"
"Major mode for Lithium sound definitions."
(setq font-lock-defaults '(agw-lithtxt-highlights)))
(fset 'agw-create-mthd-link
(kmacro-lambda-form [?i ?\[ escape ?l ?v ?f ?\( ?h ?y ?f ?\( ?i
?\] ?\{ ?: ?# ?m ?t ?h ?d ?- escape ?p ?l
?i ?\} escape ?v ?F ?- ?g ?u]
(fset 'agw-create-memb-link
(kmacro-lambda-form [?v ?$ ?h ?y ?i ?\[ escape ?A ?\] ?\{ ?\}
escape ?i ?: ?# ?m ?e ?m ?b ?- escape ?p ?v
?F ?- ?g ?u]
(fset 'agw-create-back-link
(kmacro-lambda-form [?v ?f ?\] ?h ?y ?$ ?p ?v ?F ?- ?g ?u] 0 "%d"))
(provide 'agw-lithtxt-mode)
;; EOF