Skip to content

Instantly share code, notes, and snippets.

@bamanzi
Created October 17, 2013 06:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bamanzi/7019944 to your computer and use it in GitHub Desktop.
Save bamanzi/7019944 to your computer and use it in GitHub Desktop.
Let qtmstr-outline.el support term (use margin instead of fringe)
@@ -153,19 +192,28 @@
(defvar qtmstr-outline-header-map
(progn (let ((km (make-sparse-keymap)))
- (define-key km [mouse-2] #'qtmstr-outline-on-header-click)
- (define-key km "\r" #'qtmstr-outline-on-header-return)
+ (define-key km [mouse-1] #'qtmstr-outline-on-header-click)
+ (define-key km [mouse-3] #'show-subtree)
+ (define-key km (kbd "C-c TAB") #'outline-toggle-children)
+;; (define-key km "\r" #'qtmstr-outline-on-header-return)
km)))
(fset 'qtmstr-outline-header-map qtmstr-outline-header-map)
+(define-fringe-bitmap 'qtmstr-fringe-icon-expanded [0 0 0 126 126 0 0 0])
+(define-fringe-bitmap 'qtmstr-fringe-icon-collaped [0 24 24 126 126 24 24 0])
+
(defvar qtmstr-outline-overlay-open
- (propertize "鈻?
- 'display '(when window-system left-fringe filled-square))
+ (propertize " "
+ 'display (if window-system
+ '(left-fringe qtmstr-fringe-icon-expanded)
+ '((margin left-margin) "-")))
"String displayed before a header line when it is open")
(defvar qtmstr-outline-overlay-closed
- (propertize "鈻?
- 'display '(when window-system left-fringe right-triangle))
+ (propertize " "
+ 'display (if window-system
+ '(left-fringe qtmstr-fringe-icon-collaped)
+ '((margin left-margin) "+")))
"String displayed before a header line when it is closed")
(defun qtmstr-outline-fixup-overlay (o)
@@ -176,14 +224,14 @@
(outline-on-heading-p t)))
(let ((end (overlay-end o)))
(cond ((outline-invisible-p end)
- (overlay-put o 'help-echo "mouse-2: open this outline node")
+ (overlay-put o 'help-echo "mouse-1: open this outline node")
(overlay-put o 'before-string qtmstr-outline-overlay-closed))
(t
- (overlay-put o 'help-echo "mouse-2: close this outline node")
+ (overlay-put o 'help-echo "mouse-1: close this outline node")
(overlay-put o 'before-string qtmstr-outline-overlay-open)))))
(defface qtmstr-outline-header-face
- '((t :slant italic))
+ '((t :slant italic :underline t))
"Face used for outline headings")
(defun qtmstr-outline-add-overlay-at-point ()
@@ -223,9 +271,25 @@
(when (overlay-get o 'qtmstr-outline)
(qtmstr-outline-fixup-overlay o)))))
+(defun qtmstr-outline-update-margin ()
+ (if qtmstr-outline-mode
+ (set-window-margins (selected-window) 2)
+ (set-window-margins (selected-window) nil)))
+
(defun qtmstr-outline-add-overlays ()
+ (interactive)
"Add overlays for outline headings"
+ (when (not window-system)
+ (if (car (window-margins (selected-window)))
+ (display-warning :warning
+ "`qtmstr-outline' needs to use left-margin, \n
+but currenly it seems to be already used (`linum-mode'on?).
+Anyway `qtmstr-outline' will continue to turn on."))
+ (add-hook 'window-configuration-change-hook
+ 'qtmstr-outline-update-margin nil 'local)
+ (qtmstr-outline-update-margin))
+
(add-hook 'after-change-functions #'qtmstr-outline-after-change t t)
(add-hook 'post-command-hook #'qtmstr-outline-post-command-hook t t)
(add-hook 'outline-view-change-hook #'qtmstr-outline-view-change t t)
@@ -241,12 +305,36 @@
(qtmstr-outline-add-overlay-at-point)))))))
(defun qtmstr-outline-remove-overlays ()
+ (interactive)
+ (remove-hook 'window-configuration-change-hook
+ 'qtmstr-outline-update-margin 'local)
+ (qtmstr-outline-update-margin)
+
(remove-hook 'after-change-functions #'qtmstr-outline-after-change t)
(remove-hook 'post-command-hook #'qtmstr-outline-post-command-hook t)
(save-restriction
(widen)
(remove-overlays nil nil 'qtmstr-outline t)))
+(define-minor-mode qtmstr-outline-mode
+ "Add left-fringe +/- icons and line overlays for outline-sections."
+ nil
+ " qo"
+ :require 'outline
+ :group 'outline
+ (if qtmstr-outline-mode
+ ;;turn on
+ (progn
+ (require 'qtmstr-outline)
+ (unless outline-minor-mode
+ (outline-minor-mode t))
+ (qtmstr-outline-add-overlays)
+ ;;(unless (and (boundp 'hs-minor-mode) hs-minor-mode)
+ ;; ;; avoid key conflictingve with hideshowvis
+ ;; (local-set-key [left-fringe mouse-1] 'qtmstr-outline-fringe-click))
+ )
+ (qtmstr-outline-remove-overlays)))
+
(defun qtmstr-outline-mode-hook ()
(if outline-minor-mode
(progn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment