summaryrefslogtreecommitdiff
path: root/outline-conf.el
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2021-08-12 15:24:45 +0800
committerJSDurand <mmemmew@gmail.com>2021-08-12 15:24:45 +0800
commitef5cba2079842695d24a4626dc831b6124065ac9 (patch)
tree9b26df17f8219aa7bf67606d02574c8300065989 /outline-conf.el
parent79ab6c878923f22153c2888fcf01b0fbcfc0fef6 (diff)
new: add outline configurations
Configuring outline-minor-mode, which provides an easy interface to navigate around codes. I mainly use this in Emacs Lisp buffers now. * outline-conf.el (durand-outline-regexp-alist): Each major mode could have a unique outline heading. (durand-outline-blocklist, durand-maybe-enable-outline): Don't enable outline minor mode for derived modes of the major modes in the block list. (outline-minor-mode-highlight): I want to highlight the headings. (outline-minor-mode-cycle): I like the cycling behaviour. (outline-minor-mode-map): Bind my custom key-bindings. * view-conf.el (durand-view-map): Bind to my custom map.
Diffstat (limited to 'outline-conf.el')
-rw-r--r--outline-conf.el76
1 files changed, 76 insertions, 0 deletions
diff --git a/outline-conf.el b/outline-conf.el
new file mode 100644
index 0000000..e55dafb
--- /dev/null
+++ b/outline-conf.el
@@ -0,0 +1,76 @@
+;;; outline-conf.el --- Configurations for outline -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2021 李俊緯
+
+;; Author: 李俊緯 <mmemmew@gmail.com>
+;; Keywords: convenience, files, languages, maint, matching, outlines, tools
+
+;; This program 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 3 of the License, or
+;; (at your option) any later version.
+
+;; This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; My configurations for `outline-minor-mode'.
+
+;;; Code:
+
+(require 'outline)
+
+;;;###autoload
+(defvar durand-outline-regexp-alist nil
+ "An alist that associates regular expressions with major modes
+that enable `outline-minor-mode'.")
+
+(setq durand-outline-regexp-alist
+ (list (cons 'emacs-lisp-mode
+ (rx-to-string
+ '(seq bol (>= 3 ";") (syntax ?-)) t))))
+
+;;;###autoload
+(defvar durand-outline-blocklist (list 'org-mode 'outline-mode)
+ "The list of major modes in which one should not use
+`outline-minor-mode'.")
+
+;;;###autoload
+(defun durand-maybe-enable-outline ()
+ "Enable `outline-minor-mode' if appropriate."
+ (interactive)
+ (cond
+ ((apply #'derived-mode-p durand-outline-blocklist)
+ (user-error "Should not use `outline-minor-mode' with %S"
+ major-mode))
+ ((null outline-minor-mode)
+ (let ((regexp (cdr-safe (assq major-mode durand-outline-regexp-alist))))
+ (cond
+ (regexp
+ (setq-local outline-regexp regexp))))
+ (outline-minor-mode 1)
+ (message "`outline-minor-mode' enabled"))
+ (t
+ (outline-minor-mode -1)
+ (message "`outline-minor-mode' disabled"))))
+
+(setq outline-minor-mode-highlight 'override)
+(setq outline-minor-mode-cycle t)
+
+(define-key outline-minor-mode-map (vector 3 ?\C-n) #'outline-next-visible-heading)
+(define-key outline-minor-mode-map (vector 3 ?\C-p) #'outline-previous-visible-heading)
+(define-key outline-minor-mode-map (vector 3 ?\C-f) #'outline-forward-same-level)
+(define-key outline-minor-mode-map (vector 3 2) #'outline-backward-same-level)
+(define-key outline-minor-mode-map (vector 3 1) #'outline-show-all)
+(define-key outline-minor-mode-map (vector 3 ?\C-o) #'outline-hide-other)
+(define-key outline-minor-mode-map (vector 3 ?\C-u) #'outline-up-heading)
+
+
+(provide 'outline-conf)
+;;; outline-conf.el ends here