

GitHub - snosov1/toc-org: toc-org is an Emacs utility to have an up-to-date tabl...
source link: https://github.com/snosov1/toc-org
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

README.org
About
toc-org helps you to have an up-to-date table of contents in org files without exporting (useful primarily for readme files on GitHub).
It is similar to the markdown-toc package, but works for org files.
NOTE: Previous name of the package is org-toc
. It was changed because of a
name conflict with one of the org contrib modules.
Table of Contents
Installation
via package.el
This is the simplest method if you have the package.el module (built-in since
Emacs 24.1) you can simply use M-x package-install
after setting up the MELPA
repository and then put the following snippet in your ~/.emacs file
(if (require 'toc-org nil t) (add-hook 'org-mode-hook 'toc-org-enable) (warn "toc-org not found"))
Manual
- Create folder ~/.emacs.d if you don’t have it
- Go to it and clone toc-org there
git clone https://github.com/snosov1/toc-org.git
- Put this in your ~/.emacs file
(add-to-list 'load-path "~/.emacs.d/toc-org") (if (require 'toc-org nil t) (add-hook 'org-mode-hook 'toc-org-enable) (warn "toc-org not found"))
Use
After the installation, every time you’ll be saving an org file, the first
headline with a :TOC:
tag will be updated with the current table of contents.
To add a TOC tag, you can use the command org-set-tags-command
(C-c C-q
).
In addition to the simple :TOC: tag, you can also use the following tag formats:
- :TOC_2: - sets the max depth of the headlines in the table of contents to 2 (the default)
- :TOC_2_gh: - sets the max depth as in above and also uses the GitHub-style hrefs in the table of contents (this style is default). The other supported href style is ‘org’, which is the default org style.
You can also use @
as separator, instead of _
.
Follow links
If you call M-x org-open-at-point
(C-c C-o
) when you’re at a TOC entry, the
point will jump to the corresponding heading.
Notice, that this functionality exploits the org-link-translation-function
variable. So, it won’t work if you use this variable for other purposes (i.e. it
is not nil).
You can manually disable this functionality by setting
toc-org-enable-links-opening
to nil.
Exclude headings
Headings tagged with :noexport:
will be excluded from the TOC. If you want to
preserve the heading, but strip its children (for changelog entries, for
example), you can tag it :noexport_1:
(by analogy, you can use :noexport_2:
,
:noexport_3:
, etc. for children of deeper levels). Note, though, :noexport:
has a similar meaning in org-mode
, which I hope is a Good Thing (tm). However,
:noexport_1:
and friends won’t be recognized by org-mode
as anything
special. Look at org-export-exclude-tags
variable for more details.
Shortcut for TOC tag
In your emacs’ setup, you can bind a tag :TOC:
to a binding T
:
(add-to-list 'org-tag-alist '("TOC" . ?T))
Now C-c C-q T RET
and you are done putting the :TOC:
entry.
Different href styles
Currently, only 2 href styles are supported: gh
and org
. You can easily
define your own styles. If you use the tag :TOC_2_STYLE:
(STYLE
being a
style name), then the package will look for a function named
toc-org-hrefify-STYLE
.
It should accept a heading string and a hash table of previously generated
hrefs. The table can be used to maintain href uniqueness (see
toc-org-hrefify-gh
, for example). Return value should be a href corresponding
to that heading.
E.g. for org
style it makes links to be the same as their visible text:
(defun toc-org-hrefify-org (str &optional hash) "Given a heading, transform it into a href using the org-mode rules." (toc-org-format-visible-link str))
Example
* About * Table of Contents :TOC: - [[#about][About]] - [[#installation][Installation]] - [[#via-packageel][via package.el]] - [[#manual][Manual]] - [[#use][Use]] - [[#example][Example]] * Installation ** via package.el ** Manual * Use * Example
Recommend
-
10
ts.el ts is a date and time library for Emacs. It aims to be more convenient than patterns like (string-to-number (format-time-string "%Y")) by providing easy accessors, like (ts-year (ts-now))...
-
11
Pythonic Utility functions for writing pythonic emacs package. Installation You can install this package form Melpa M-x package-install RET pythonic RET
-
10
Overview List-manipulation utility functions for Emacs. Quickstart (require 'list-utils) (list-utils-flatten '(1 2 (3 4 (5 6 7)))) ;; '(1 2 3 4 5 6 7) (list-utils-depth '(1 2 (3 4 (5 6 7)))) ;; 3 (let ((...
-
2
Date-fns vs MomentJS: Choosing the Right Date Utility LibraryComparing popular JavaScript date libraries.MomentJS is one of the most used JavaScript date li...
-
6
PC gamers rejoice – we finally have a launch date for the Intel Arc GPU By Jess Weatherbed published about 2 hours ago Laptops will be...
-
8
README.md
-
8
Steam Updates Database With Possible Among Us VR Release Date A...
-
6
Poco C40 launch date and prices have been revealed
-
10
Snapdragon 8 Gen 2 SoC features and launch date have been revealed
-
7
5 Android Utility Apps You Should Have On Your Phone At All Times
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK