Git Product home page Git Product logo

outline-toc.el's Introduction

outline-toc.el

An Emacs extension that will render a "table of contents" for outline-mode "compatible" buffers (i.e. those that respond to outline-hide-body).

This TOC will show the sections in the document, highlighting the one that you're editing in the master document. The whole idea is to give you context as you're editing a large document (e.g. a markdown file or something).

Quickstart

Open up a supported file and run outline-toc-mode. This should open up a new window with a table of contents for your file. As you move around in the source buffer, the TOC should highlight the section you're in.

Here's an example showing outline-toc-mode while editing the markdown source for a chapter in one of my books:

Screencast

Current status

outline-toc works, more or less. You can open up the TOC and it'll stay synchronized with your master doc. It could certainly use some polish, though.

Right now this is known to work with markdown-mode, org-mode, and outline-mode files. It may work with others. I'd like it to work with restructured text, but there seem to be some problems there.

Caveat emptor, and a call to arms

In my estimation, this is currently built on a bit of a hack. outline-toc relies on outline-hide-body to show the section headers of documents; it doesn't bring any extra magic to the mix. Maybe there are better approaches, and I'm certainly open to ideas, PRs, etc.

Similarly, the "sidebar" buffer is lifted wholesale from minimap. Many Emacs packages implement similar functionality, and it would be nice if there was a shared implementation of "sidebars". Maybe this is unrealistic for some reason, but if someone has a re-usable library for this functionality I'd be eager to try it.

outline-toc.el's People

Contributors

conao3 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

outline-toc.el's Issues

Screenshots?

It would be nice to have some screenshots. :)

Example code

Hey it's me again. I was inspired by org-panes to modify the code I mentioned before, and this is the result. It's a really nice way to browse around large org files. I thought I'd share it here in case you find the code useful or inspirational. :) Just open an Org file and run ap/open-tree-view.

(defun ap/open-tree-view ()
  "Open a clone of the current buffer to the left, resize it to
30 columns, and bind <mouse-1> to jump to the same position in
the base buffer."
  ;; http://emacs.stackexchange.com/questions/9530/how-can-i-get-an-org-mode-outline-in-a-2nd-buffer-as-a-dynamic-table-of-contents
  ;; TODO: Make this use navi-mode, which handles most of this already
  (interactive)
  (let ((new-buffer-name (concat "<tree>" (buffer-name))))

    ;; Create tree buffer
    (split-window-right 60)
    (if (get-buffer new-buffer-name)

        ;; Use existing tree buffer
        (switch-to-buffer new-buffer-name)

      (progn
        ;; Make new tree buffer
        (clone-indirect-buffer new-buffer-name nil t)
        (switch-to-buffer new-buffer-name)
        (read-only-mode)
        (hide-body)
        (toggle-truncate-lines)

        ;; Do this twice in case the point is in a hidden line
        (dotimes (_ 2 (forward-line 0)))

        ;; Map keys
        (use-local-map (copy-keymap outline-mode-map))
        (local-set-key (kbd "q") '(lambda ()
                                    (interactive)
                                    (let ((buffer (current-buffer)))
                                      (delete-window)
                                      (kill-buffer buffer))))
        (mapc (lambda (key) (local-set-key (kbd key) 'ap/jump-to-point-and-show))
              '("<mouse-1>" "RET"))))))

(defun ap/jump-to-point-and-show ()
  "Switch to a cloned buffer's base buffer and move point to the
cursor position in the clone."
  (interactive)
  (let ((buffer (buffer-base-buffer)))
    (unless buffer
      (error "Must be in a cloned buffer."))
    (when (and (outline-subheadings-p)
               (not (outline-subheadings-visible-p)))
      (outline-show-children))
    (let ((pos (point))
          (window (car (get-buffer-window-list buffer))))
      (if window
          (select-window window)
        (other-window 1)
        (switch-to-buffer buffer))
      (widen)
      (goto-char pos)
      (org-show-entry)
      ;; (org-narrow-to-subtree)
      (narrow-to-region (org-entry-beginning-position) (org-entry-end-position))
      )))

Missing outline-toc-setup-hooks definition?

I found function; outline-toc-setup-hooks is not defined anywhere.

As a result, turn off outline-toc-mode occurs error.

Here is backtrace.

Debugger entered--Lisp error: (void-function outline-toc-setup-hooks)
  outline-toc-setup-hooks(t)
  outline-toc-mode(toggle)
  funcall-interactively(outline-toc-mode toggle)
  call-interactively(outline-toc-mode record nil)
  command-execute(outline-toc-mode record)
  counsel-M-x-action("outline-toc-mode")
  ivy-call()
  ivy-read("M-x " [## hasNextPage origami-hide-node-overlay epg-context-signers helm-candidates-in-buffer dap-ui-breakpoint-log-message package-lint--sane-prefixes message-required-headers denied edebug-trace forge-gogs-repository--eieio-childp tramp-find-user treemacs-project->path-status markdown-match-bold magit-wip-buffer-backed-up /home/conao/Documents/org/\#+date: tramp-gvfs-handle-copy-file treemacs-next-neighbour forge--color-luminance lsp--check-document-changes-version persistent pdfauthor lsp-solargraph-references application gnus-undo-force-boundary which-key-side-window-max-height implemented outline-toc-font-face org-agenda-regexp-filter-preset vc-git-conflicted-files conf-space-mode-map tramp-cleanup cl--struct-epg-signature-p shr-parse-image-data perm-tmp f-directory\? Edebug\ All\ Defs helm-kill-regexp-as-sexp scale \' nnoo-import-1 helm-grep-mode-jump-other-window-forward tramp-cache-data always-end problems align-set-vhdl-rules \. helm-buffers--get-tab-from-name \0 \1 ...] :predicate #f(compiled-function (sym) #<bytecode 0x13898d1>) :require-match t :history counsel-M-x-history :action counsel-M-x-action :keymap (keymap (67108908 . counsel--info-lookup-symbol) (67108910 . counsel-find-symbol)) :initial-input nil :caller counsel-M-x)
  counsel-M-x()
  funcall-interactively(counsel-M-x)
  call-interactively(counsel-M-x nil nil)
  command-execute(counsel-M-x)

How to resolve it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.