Some features shared by all programming languages and several languages with light configurations.
A single hook holding those functions which should be run in every code buffer.
We have a number of turn-on-* functions since it’s advised that lambda functions not go in hooks. Repeatedly evaling an add-to-list with a hook value will repeatedly add it since there’s no way to ensure that a lambda doesn’t already exist in the list.
(defvar starter-kit-coding-hook nil
"Hook that gets run on activation of any programming mode.")
(defun starter-kit-auto-fill ()
(setq-local comment-auto-fill-only-comments nil)
(auto-fill-mode t))
(add-hook 'starter-kit-coding-hook 'starter-kit-auto-fill)
(defun starter-kit-turn-on-flyspell ()
(flyspell-prog-mode))
(add-hook 'starter-kit-coding-hook 'starter-kit-turn-on-flyspell)
(defun starter-kit-turn-on-hs ()
(hs-minor-mode)
(when (window-system)
(hideshowvis-enable)
(hideshowvis-symbols)))
;; (add-hook 'starter-kit-coding-hook 'starter-kit-turn-on-hs)
(defun starter-kit-turn-on-linum ()
(interactive)
(linum-mode 1))
(add-hook 'starter-kit-coding-hook 'starter-kit-turn-on-linum)
(setq fic-highlighted-words '("FIXME" "TODO" "BUG" "KLUDGE" "DEBUG"))
(add-hook 'starter-kit-coding-hook 'turn-on-fic-mode)
(defun starter-kit-turn-on-longline ()
(interactive)
(visual-line-mode 1)
(adaptive-wrap-prefix-mode 1))
(defun starter-kit-turn-off-longline ()
(interactive)
(visual-line-mode -1)
(adaptive-wrap-prefix-mode -1))
(add-hook 'starter-kit-coding-hook 'starter-kit-turn-on-longline)
(defun run-starter-kit-coding-hook ()
"Enable things that are convenient across all coding buffers."
(run-hooks 'starter-kit-coding-hook))
(add-hook 'prog-mode-hook 'run-starter-kit-coding-hook)
show-paren-mode and electric-pair-mode are lighter than smartparens and minimally intrusive.
(show-paren-mode 1)
(electric-pair-mode 1)
(setq electric-pair-open-newline-between-pairs t)
(setq electric-pair-pairs
'((?\" . ?\")
(?{ . ?})))
(setq which-func-modes
'(python-mode c-mode c++-mode f90-mode fortran-mode emacs-lisp-mode
org-mode perl-mode ruby-mode scheme-mode
rst-mode markdown-mode LaTeX-mode latex-mode))
(defun starter-kit-which-func-format ()
(if (eq major-mode 'lisp-interaction-mode)
(progn
(setq-local header-line-format nil)
(setq-local mode-line-misc-info
(assq-delete-all 'which-func-mode mode-line-misc-info)))
(unless which-function-mode
(which-function-mode 1))
(setq-local which-func-unknown "n/a")
(setq-local header-line-format
'((which-func-mode ("" which-func-format " "))))
(setq-local mode-line-misc-info
(assq-delete-all 'which-function-mode mode-line-misc-info))
(setq-local mode-line-misc-info
(assq-delete-all 'which-func-mode mode-line-misc-info))))
;; imenu should be setup before which function. so append the hook
(mapc
(lambda (mode)
(add-hook (intern (format "%s-hook" (symbol-name mode)))
'starter-kit-which-func-format t))
which-func-modes)
(add-hook 'cmake-mode-hook 'cmake-font-lock-activate)
(add-hook 'cmake-mode-hook 'starter-kit-turn-on-linum)
(defun my-cmake-conf ()
(local-set-key (kbd "C-h f") #'cmake-help))
(add-hook 'cmake-mode-hook #'my-cmake-conf)
I’d like to ignore case when using ido to complete read.
(with-eval-after-load 'cmake-mode
(defun cmake-help ()
"Queries for any of the four available help topics and prints out the approriate page."
(interactive)
(let* ((default-entry (downcase (word-at-point)))
(command-list (cmake-get-list "command"))
(variable-list (cmake-get-list "variable"))
(module-list (cmake-get-list "module"))
(property-list (cmake-get-list "property"))
(all-words (append command-list variable-list module-list property-list))
(input (completing-read
"CMake command/module/variable/property: " ; prompt
all-words ; completions
nil ; predicate
t ; require-match
default-entry ; initial-input
'cmake-help-complete-history
)))
(if (string= input "")
(error "No argument given")
(if (member input command-list)
(cmake-command-run "--help-command" input "*CMake Help*")
(if (member input variable-list)
(cmake-command-run "--help-variable" input "*CMake Help*")
(if (member input module-list)
(cmake-command-run "--help-module" input "*CMake Help*")
(if (member input property-list)
(cmake-command-run "--help-property" input "*CMake Help*")
(error "Not a know help topic.") ; this really should not happen
))))))))
To automatically remap capslock to ctrl and shift-capslock to original capslock every time you start up PC:
- Click the Start button Picture of the Start button , click All Programs, right-click the Startup folder, and then click Open.
- Right-click the starter-kit-ahk script, and then click Create Shortcut. The new shortcut appears in the same location as the original item.
- Drag the shortcut into the Startup folder.
(setq ahk-syntax-directory (concat starter-kit-dir "src/ahk-mode/Syntax/"))
(add-to-list 'auto-mode-alist
'("\\.ahk$" . ahk-mode))
RELAX NG is a simple schema language for XML, based on [RELAX] and [TREX]. A RELAX NG schema specifies a pattern for the structure and content of an XML document. A RELAX NG schema thus identifies a class of XML documents consisting of those documents that match the pattern.
Two syntaxes have been defined for RELAX NG. The original syntax uses XML; with this syntax an RELAX NG schema is itself an XML document. Subsequently, a compact non-XML syntax has been defined.
The compact format file has a “rnc” suffix and rnc-mode provide a major mode for these files.
(add-to-list 'auto-mode-alist '("\\.rnc\\'" . rnc-mode))
I don’t like nxml-mode at all. It’s too heavy, just use sgml-mode instead.
(defalias 'xml-mode 'sgml-mode
"Use `sgml-mode' instead of `nxml-mode'.")
(defun my-xml-config ()
(modify-syntax-entry ?_ "w"))
(add-hook 'sgml-mode-hook 'my-xml-config)
(defun my-pp-xml (begin end)
"Pretty format XML markup in region. The function inserts
linebreaks to separate tags that have nothing but whitespace
between them. It then indents the markup by using nxml's
indentation rules."
(interactive "r")
(save-excursion
(goto-char begin)
(while (search-forward-regexp "\>[ \\t]*\<" nil t)
(backward-char) (insert "\n"))
(indent-region begin end)))
The original comment uncomment command is not stable.
(defun my-comment-uncomment-xml (beg end)
(interactive "P")
(let ((beg0 (save-excursion
(goto-char beg)
(line-beginning-position)))
(end0 (save-excursion
(goto-char (1- end))
(line-end-position))))
(if (my-xml-commented-p beg0 end0)
(my-uncomment-xml-region beg0 end0)
(my-comment-xml-region beg0 end0))))
(defun my-xml-commented-p (beg end)
(string-match-p ".*<!--.*-->.*" (buffer-substring-no-properties beg end)))
(defun my-comment-xml-line ()
(interactive)
(save-excursion
(back-to-indentation)
(insert "<!-- ")
(end-of-line)
(skip-syntax-backward " " (line-beginning-position))
(insert " -->")))
(defun my-uncomment-xml-line ()
(interactive)
(save-excursion
(back-to-indentation)
(re-search-forward "<!-- *" nil t)
(let (i0 i1)
(setq i1 (point)
i0 (search-backward "<"))
(delete-region i0 i1))
(end-of-line)
(forward-line)
(re-search-backward "-->" nil t)
(skip-syntax-backward " " (line-beginning-position))
(let (i0 i1)
(setq i0 (point)
i1 (search-forward ">"))
(delete-region i0 i1))))
(defun my-comment-xml-region (beg end &optional arg)
(interactive "r")
(let ((l1 (line-number-at-pos (1- end))))
(save-excursion
(goto-char beg)
(while (<= (line-number-at-pos) l1)
(my-comment-xml-line)
(next-logical-line)))))
(defun my-uncomment-xml-region (beg end &optional arg)
(interactive "r")
(let ((l1 (line-number-at-pos (1- end))))
(save-excursion
(goto-char beg)
(while (<= (line-number-at-pos) l1)
(my-uncomment-xml-line)
(next-logical-line)))))
(add-to-list 'auto-mode-alist '("\\.m\\'" . octave-mode))
(add-to-list 'auto-mode-alist '("\\.\\(i\\|swg\\)\\'" . swig-mode))