Showing preview only (1,071K chars total). Download the full file or copy to clipboard to get everything.
Repository: ndwarshuis/om.el
Branch: master
Commit: e348f446746b
Files: 25
Total size: 1.0 MB
Directory structure:
gitextract_xakltvns/
├── .emacs/
│ ├── 28.2/
│ │ └── straight/
│ │ └── versions/
│ │ └── default.el
│ ├── 29.3/
│ │ └── straight/
│ │ └── versions/
│ │ └── default.el
│ └── 30.1/
│ └── straight/
│ └── versions/
│ └── default.el
├── .github/
│ └── workflows/
│ └── test.yml
├── .gitignore
├── CHANGELOG.md
├── LICENSE
├── Makefile
├── README.md
├── bench/
│ ├── org-ml-bench-fw.el
│ └── org-ml-benchmarks.el
├── dev/
│ ├── org-ml-cookbook.el
│ ├── org-ml-docs.el
│ ├── org-ml-examples.el
│ ├── org-ml-test-common.el
│ ├── org-ml-test-external.el
│ └── org-ml-test-internal.el
├── docs/
│ ├── api-reference.md
│ └── cookbook.md
├── env-28.2.yml
├── env-29.3.yml
├── env-30.1.yml
├── init.el
├── org-ml-macs.el
└── org-ml.el
================================================
FILE CONTENTS
================================================
================================================
FILE: .emacs/28.2/straight/versions/default.el
================================================
(("dash.el" . "721436b04da4e2795387cb48a98ac6de37ece0fd")
("el-get" . "f220df34333fdb363b84b28f4ed4a5575341bf45")
("emacs-buttercup" . "e4fb7cd560d27d8879a2c7739ee96946adec2df8")
("emacsmirror-mirror" . "d9919dfe6eede6ff668614b23f64cfef0f954c48")
("gnu-elpa-mirror" . "e59499eeb86979ef2b41f004b11c0e712f6354b3")
("melpa" . "fd3bb4b191bf416dd419c5c76d510c7f5890e673")
("nongnu-elpa" . "c7b774608a8b17b5e95a096317d12fae7dc31b68")
("org" . "233a0ced97366090c31ef94562879bb2f729b120")
("s.el" . "dda84d38fffdaf0c9b12837b504b402af910d01d")
("straight.el" . "b3760f5829dba37e855add7323304561eb57a3d4"))
:gamma
================================================
FILE: .emacs/29.3/straight/versions/default.el
================================================
(("dash.el" . "721436b04da4e2795387cb48a98ac6de37ece0fd")
("el-get" . "f220df34333fdb363b84b28f4ed4a5575341bf45")
("emacs-buttercup" . "e4fb7cd560d27d8879a2c7739ee96946adec2df8")
("emacsmirror-mirror" . "d9919dfe6eede6ff668614b23f64cfef0f954c48")
("gnu-elpa-mirror" . "e59499eeb86979ef2b41f004b11c0e712f6354b3")
("melpa" . "fd3bb4b191bf416dd419c5c76d510c7f5890e673")
("nongnu-elpa" . "c7b774608a8b17b5e95a096317d12fae7dc31b68")
("org" . "233a0ced97366090c31ef94562879bb2f729b120")
("s.el" . "dda84d38fffdaf0c9b12837b504b402af910d01d")
("straight.el" . "b3760f5829dba37e855add7323304561eb57a3d4"))
:gamma
================================================
FILE: .emacs/30.1/straight/versions/default.el
================================================
(("dash.el" . "721436b04da4e2795387cb48a98ac6de37ece0fd")
("el-get" . "f220df34333fdb363b84b28f4ed4a5575341bf45")
("emacs-buttercup" . "c0764a764cf088dcb5132c44d5864b22d7723765")
("emacsmirror-mirror" . "d9919dfe6eede6ff668614b23f64cfef0f954c48")
("gnu-elpa-mirror" . "e59499eeb86979ef2b41f004b11c0e712f6354b3")
("melpa" . "fd3bb4b191bf416dd419c5c76d510c7f5890e673")
("nongnu-elpa" . "c7b774608a8b17b5e95a096317d12fae7dc31b68")
("org" . "233a0ced97366090c31ef94562879bb2f729b120")
("s.el" . "dda84d38fffdaf0c9b12837b504b402af910d01d")
("straight.el" . "b3760f5829dba37e855add7323304561eb57a3d4"))
:gamma
================================================
FILE: .github/workflows/test.yml
================================================
name: CI
on: [push]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
emacs_version:
- '28.2'
- '29.3'
- '30.1'
steps:
- uses: actions/checkout@v2
- uses: purcell/setup-emacs@master
with:
version: ${{ matrix.emacs_version }}
- name: Run tests
run: |
make install
make
================================================
FILE: .gitignore
================================================
*.elc
.emacs/*/straight/build
.emacs/*/straight/repos
.emacs/*/straight/build-cache.el
================================================
FILE: CHANGELOG.md
================================================
# Changelog
## 6.0.2
- fix org-ml-match-do* form bug
## 6.0.1
- add tests for emacs 30.1
## 6.0.0
This is a major update for org 9.7, which has been heavily optimized with a new
syntax tree API. This new version of org-ml takes advantage of this new API
(which is much faster) but also breaks several things.
summary of breaking changes
- `org-ml-planning-*` functions have been removed (they are no longer necessary)
- the supercontents data structure (for
`org-ml-headline-get/set/map-supercontents) has been updated and rewritten.
See docstring for `org-ml-headline-get-supercontents` for details. TLDR is
that it now handles planning and node properties. This was done partly to
better handle whitespace (which was not done correctly previously) and also to
take advantage of performance improvements in the headline node type (see
below for `org-ml-update-supercontents`)
- all previous depreciated functions have been removed
- and `org-ml-timestamp-get/set-range` have been renamed to
`org-ml-timestamp-get/set-length`
- `org-ml-parse-habits` has been removed, this is now elegantly handled by
org-element itself. See `org-ml-timestamp-get/set/map-deadline` instead.
- `org-ml-headline-get/set/map-node-properties` now use a list of string pairs
like `(KEY VAL)` instead of raw node-property nodes.
- `org-ml-timestamp-set-length` now takes a unit argument
- `org-ml-clone-node` has been removed
- `org-ml-unixtime-to-time-long/short` have been combined into
`org-ml-unixtime-to-timelist` which takes a flag to determine if the hours and
minutes should be included
summary of added features
- added higher-level timestamp-diary functions for start and end time
manipulation (new in org 9.7)
- `org-ml-timestamp-get/set/map-deadline` which manipulates what is commonly
called "habits" (new in org 9.7)
- `org-ml-update-supercontents` and `org-ml-update-supersection` which are two
heavily-optimized functions which take advantage of the new lazy evalulation
in org 9.7; use these to update headline contents without touching the
headline itself
- memoization for builder functions
- ability to switch between pure and impure evaluation (the latter is faster but
less safe); see `org-ml-use-impure`
bug fixes and refactorizations
- added missing tests for purity
- fixed many whitespace handling errors
- use conda to pin exact emacs version for local development
- use straight to pin exact versions of all dependencies
- remove lispy dependency
## 5.8.8
- fix list-like syntax in secondary string parsing
## 5.8.7
- use strings for `org-ml-build-property-drawer!` arguments
## 5.8.6
- bugfixes
## 5.8.5
- make docstring clearer
## 5.8.4
- don't parse bold text as a headline
## 5.8.3
- fix typo in README.md
## 5.8.2
- fix blank table cell bug
## 5.8.1
- fix typo
## 5.8.0
- make myers diff algorithm use linear space
- fix a bunch of compiler warnings for emacs 28+
## 5.7.3
- fix leaky abtraction bug
## 5.7.2
- fix incompatibility with org v9.5 (note: 9.5 not fully tested yet)
## 5.7.1
- add `org-ml-remove-parent(s)`
## 5.7.0
- add functions/checks for `org-data` nodes
## 5.6.2
- add explicit test path for emacs 27.2/org-mode 9.4
## 5.6.1
- make `org-ml-from-string` work correctly with all types and inputs
## 5.6.0
- add get/set/map functions for timestamp repeaters and warnings
- add optional switch for habit parsing
## 5.5.4
- fix `org-ml-headline-set-node-property` nil property bug
## 5.5.3
- fix missing zero-length ending timestamps
## 5.5.2
- fix compile warnings for `org-ml-macs.el`
## 5.5.1
- fix potential merge sort stack overflow
## 5.5.0
- reorganized headline/subtree batch functions (and depreciated old names)
## 5.4.3
- fixed nested headline parsing for `org-ml-get-headlines` et al
## 5.4.2
- make indent/outdent/promote/demote functions more accurate/faster
- further optimizations and additional benchmarks
## 5.4.1
- improve performance of string insertion and headline batch updating
## 5.4.0
- add pattern memoization to match function family
- numerous performance enhancements including:
- remove majority of closures in anaphoric forms (eg `make-byte-code`)
- implement faster macros for plists
- improve timestamp processing
- remove equality checking from `org-ml~update`
- streamline headline batch functions (eg `org-ml-do-headlines` et al)
## 5.3.0
- add `org-ml-get-properties`
- add `org-ml-item-get/set/map-paragraph`
- make `org-ml-get-all-properties` public
- numerous bug fixes and performance enhancments
## 5.2.0
- add benchmark framework
- add intermediate functions to control Myers diff algorithm application
- fix potential infinite loop using native `equal` function for node comparison
## 5.1.0
- fixed array overflow error in myers diff code
- add affiliated keywords to polymorphic property interface and builder
functions
## 5.0.2
- fixed active timestamp bug for closed planning nodes
- use Myers diff algorithm for update functions
## 5.0.1
- rearrange reference files
- use buttercup for testing
## 5.0.0
- add robust headline logbook and contents function
- rename indent/unindent functions to better reflect native org function naming
conventions
- add `org-ml-from-string`
- improve subtree parsing performance
- fix whitespace errors for
`org-ml-headline-set-planning/node-properties/supercontents` functions
## 4.0.1
- fix `org-ml-parse-this-table-row` and `org-ml-parse-table-row-at`
beyond first row of table
## 4.0.0
- add `org-ml-get-parents`
- add `org-ml-headline-get-logbook-loose` and `org-ml-headline-get-contents`
- removed old `org-ml-headline-X-logbook` functions and replaced them with
`org-ml-headline-X-logbook-drawer` which can be made aware of other drawers
other than "LOGBOOK" or nothing
- add `org-ml-clone-n`
## 3.0.2
- Update dependencies
- Fix bugs
## 3.0.1
- Fix bugs
- Don't use `nreverse` unless needed
- Don't crash when `org-ml-headline-get-node-property` should return nil
## 3.0.0
- Update for org-mode 9.3
## 2.0.1
- Fixed byte compile
- Clean up docstrings
## 2.0.0
- Renamed from `om.el` to `org-ml` (org-metalanguage)
- Renamed functions to be more consistent
- `org-ml-get-headlines` and friends to `org-ml-parse-headlines`
- `org-ml-do-headlines` and friends to `org-ml-update-headlines`
- Add POSIX ERE-like regexp syntax to `org-ml-match` and friends
- Add affiliated keyword support
- Numerous bug fixes
================================================
FILE: LICENSE
================================================
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
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 <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
================================================
FILE: Makefile
================================================
EMACS ?= emacs -Q --batch --load init.el -L .
RM ?= rm -f
all: test
# run all tests with both interpreted and compiled org-ml functions
test:
${MAKE} unit
${MAKE} compile
# build docs for org-ml
docs:
${EMACS} -L dev \
-l dev/org-ml-docs.el \
-f create-docs-files
# run internal (stateless) tests with interpreted org-ml functions
internal:
${EMACS} -L dev \
-l dev/org-ml-test-internal.el \
-f buttercup-run-discover
# run external (stateful) tests with interpreted org-ml functions
external:
${EMACS} -L dev \
-l dev/org-ml-test-external.el \
-f buttercup-run-discover
# run tests with interpreted org-ml functions
unit:
${EMACS} -L dev \
-l dev/org-ml-test-external.el \
-l dev/org-ml-test-internal.el \
-f buttercup-run-discover
# run tests with compiled org-ml functions
compile:
${MAKE} build
${MAKE} unit
${MAKE} clean-elc
# run and print benchmark results using compile org-ml functions
benchmark:
${EMACS} build
${EMACS} -L bench \
-l bench/org-ml-benchmarks.el \
-f org-ml-bench-run
${MAKE} clean-elc
# remove compiled lisp files
clean-elc:
${RM} *.elc
# byte-compile all org-ml lisp files
build:
${EMACS} -f compile-target
# install all development packages for the current version
install:
${EMACS} --eval '(print "Install finished")'
# write lockfile for current emacs version given each repo dependency
freeze:
${EMACS} -f straight-freeze-versions
thaw:
${EMACS} -f straight-thaw-versions
.PHONY: all test docs unit
================================================
FILE: README.md
================================================
# org-ml  
A functional API for org-mode inspired by
[@magnars](https://github.com/magnars)'s
[dash.el](https://github.com/magnars/dash.el) and
[s.el](https://github.com/magnars/s.el) libraries.
# Installation
Install from MELPA:
```
M-x package-install RET org-ml RET
```
Alternatively, clone this repository to somewhere in your load path:
```
git clone https://github.com/ndwarshuis/org-ml ~/somewhere/in/load/path
```
Then require in your emacs config:
```
(require 'org-ml)
```
## Dependencies
- emacs (28.2, 29.3, 30.1)
- org-mode (9.7.9)
- dash (2.17.0)
- s (1.13.0)
Explicit versions noted above have been tested. Other versions may work but are
not currently supported.
Notably, *only* org 9.7.x and above will work (9.6 and below will absolutely
break).
# Motivation
Org-mode comes with a powerful, built-in parse-tree generator specified in
`org-element.el`. The generated parse-tree is simply a heavily-nested list which
can be easily manipulated using (mostly pure) functional code. This contrasts
the majority of functions normally used to interface with org-mode files, which
are imperative in nature (`org-insert-headine`, `outline-next-heading`, etc) as
they depend on the mutable state of Emacs buffers. In general, functional code
is
([arguably](https://en.wikipedia.org/wiki/Functional_programming#Comparison_to_imperative_programming))
more robust, readable, and testable, especially in use-cases such as this where
a stateless abstract data structure is being transformed and queried.
The `org-element.el` provides a minimal API for handling this parse-tree in a
functional manner, but does not provide higher-level functions necessary for
intuitive, large-scale use. The `org-ml` package is designed to provide this
API. Furthermore, it is highly compatible with the `dash.el` package, which is a
generalized functional library for emacs-lisp.
# Org-Element Overview
Parsing a buffer with the function `org-element-parse-buffer` will yield a parse
tree composed of nodes. Nodes have types and properties associated with them.
See [the org-element API
documentation](https://orgmode.org/worg/dev/org-element-api.html#attributes) for
a list of all node types and their properties (also see the [terminology
conventions](#terminology) and [property omissions](#properties) used in this
package).
Each node is represented by a list where the first member is the type and the
second member is a plist describing the node's properties:
``` emacs-lisp
(type (:prop1 value1 :prop2 value2 ...))
```
Node types may be either leaves or branches, where branches may have zero or
more child nodes and leaves may not have child nodes at all. Leaves will always
have lists of the form shown above. Branches, on the other hand, have their
children appended to the end:
``` emacs-lisp
(type (:prop1 value1 :prop2 value2) child1 child2 ...)
```
In addition to leaves and branches, node types can belong to one of
two classes:
- Objects: roughly correspond to raw, possibly-formatted text
- Elements: more complex structures which may be built from objects
Within the branch node types, there are restrictions of which class is allowed
to be a child depending on the type. There are three of these restrictions:
- Branch element with child elements (aka 'greater elements'): these are element
types that are generally nestable inside one another (eg headlines,
plain-lists, items)
- Branch elements with child objects (aka 'object containers'): these are
element types that hold textual information (eg paragraph)
- Branch objects with child objects (aka 'recursive objects'): these are object
types used primarily for text formating (bold, italic, underline, etc)
Note: it is never allowed for an element type to be a child of a branch object
type.
# Conventions
## Terminology
- 'node' is a vertex in the parse tree, where 'element' and 'object' are two
classes used to describe said vertex
- 'child' and 'children' are used here instead of 'content' and 'contents'
- 'branch' is a node that has or can have other nodes in it (`org-element`
mostly uses 'container' to describe these)
- 'leaf' is a node without other nodes in it (opposite of branch)
## Properties
All properties specified by `org-element.el` are readable by this API (eg one
can query them with functions like `org-ml-get-property`).
The properties `:begin`, `:end`, `:contents-begin`, `:contents-end`, `:parent`,
and `post-affiliated` are not settable by this API as they are not necessary for
manipulating the textual representation of the parse tree. In addition to these,
some properties unique to certain types are not settable for the same reason.
Each type's build function (`org-ml-build-X`) describes the properties that are
settable.
See `org-ml-remove-parent` and `org-ml-remove-parents` for specific information
and functions regarding the `:parent` property, why it can be annoying, and when
you would want to remove it.
## Threading
Each function that operates on an element/object will take the element/object as
its right-most argument. This allows convenient function chaining using
`dash.el`'s right-threading operators (`->>` and `-some->>`). The examples in
the [API reference](docs/api-reference.md) almost exclusively demonstrate this
pattern. Additionally, the right-argument convention also allows convenient
partial application using `-partial` from `dash.el`.
## Higher-order functions
Higher-order functions (functions that take other functions as arguments) have
two forms. The first takes a (usually unary) function and applies it:
``` emacs-lisp
(org-ml-map-property :value (lambda (s) (concat "foo" s)) node)
(org-ml-map-property :value (-partial concat "foo") node)
```
This can equivalently be written using an anaphoric form where the original
function name is appended with `*`. The symbol `it` carries the value of the
unary argument (unless otherwise specified):
``` emacs-lisp
(org-ml-map-property* :value (concat "foo" it) node)
```
## Side effect functions
All functions that read and write from buffers are named like
`org-ml-OPERATION-THING-at` where `OPERATION` is some operation to be performed on
`THING` in the current buffer. All these functions take `point` as one of their
arguments to denote where in the buffer to perform `OPERATION`.
All of these functions have current-point convenience analogues that are named
as `org-ml-OPERATION-this-THING` where `OPERATION` and `THING` carry the same
meaning, but `OPERATION` is done at the current point and `point` is not an
argument to the function.
For the sake of brevity, only the former form of these functions are given in
the [API reference](docs/api-reference.md).
# Usage
For comprehensive documentation of all available functions see the [API
reference](docs/api-reference.md).
## Habits
Since org 9.7, habits are stored in `:repeater-deadline-unit` and
`:repeater-deadline-value` of `timestamp` nodes. "Deadline" refers to the last
bit in the repeater of a timestamp (ie the "3d" in "[2019-01-01 Tue 12:00
+1d/3d]").
See `org-ml-timestamp-get/set/map-deadline` to access and manipulate these.
# Performance
Benchmarking this library is still in the early stages.
Intuitively, the most costly operations are going to be those that go
back-and-forth between raw buffer text (here called "buffer space") and its node
representations (here called "node space") since those involve complicated
string formating, regular expressions, buffer searching, etc (examples:
`org-ml-parse-this-THING`, `org-ml-update-this-THING` and friends). Once the
data is in node space, execution should be very fast since nodes are just lists.
Thus if you have performance-intensive code that requires many small edits to
org-mode files, it might be better to use org-mode's built-in functions. On the
other hand, if most of the complicated processing can be done in node space
while limiting the number of conversions to/from buffer space, `org-ml` will be
much faster.
To be more scientific, the current tests in the suite (see
[here](bench/org-ml-benchmarks.el)) seem to support the following conclusions
when comparing `org-ml` to equivalent code written using built-in org-mode
functions (in line with the intuitions above):
* reading data (a one way conversion from buffer to node space) is up to an
order of magnitude slower, specifically when the data to be obtained isn't
very large (eg, reading the TODO state from a headline)
* text manipulations can be update to 10x slower *or faster* depending on what
they are:
* large edits like headline level changing are slower in `org-ml`
* updating headline todo and tags are faster in `org-ml`
* complex operations that involve lots of different functions tend to be
faster in `org-ml` (since there are more list operations vs buffer edits)
* changing the contents of headlines can be as fast or faster in `org-ml`,
especially when using memoization and `org-ml-update-supercontents` (see
below).
To run the benchmark suite:
``` sh
make benchmark
```
## Deferred Properties
### Overview
Starting with org 9.7, `org-element`'s abstract syntax tree uses lazy evaluation
for several text-heavy operations. Thus the tree that `org-ml` consumes may have
unevaluated (aka "deferred") properties in it. For the most part, this will not
affect user experience, but understanding this will help in optimizing
performance, as preventing lazy properties from being unnecessarily resolved
will lead to significant performance gains.
As of version 9.7.9, the properties which are deferred are:
* most properties in headlines (all except for :pre-blank and the properties in
`org-element--standard-properties`)
* the :value property for code and verbatim nodes
Since most of the deferred properties are in headlines, and because headlines
are so prevalent, the remainder of this discussion will focus on headlines.
Accessing any deferred property in a headline will trigger that property to be
resolved, which is slow (as of 9.7.9 this often results in multiple properties
being resolved at once due to the interconnected nature of how a headilne is
parsed). In `org-ml` this means using `org-ml-get-property` or similar, as well
as `org-ml-to-string` which necessarily needs to read all properties to create a
string. Setting a property will resolve all properties, since (as noted above)
many deferred headline properties depend on others.
### Optimizations in org-ml
With regard to buffer editing (ie `org-ml-update-X` functions) this also means
that any operation that does *not* edit the headline itself can be much faster
under this new lazy paradigm. Examples of this include updating CLOSED or
SCHEDULED timestamps, editing the logbook, adding properties like Effort, or
adding other contents between these and the next headline. Unlike previous
versions of `org-ml` and `org` manipulating these would have involved parsing
the headline, parsing the stuff inside the headline, editing the stuff inside
the headline, then writing out a new headline. In 9.7, we can bypass most of the
headline parsing in this situation.
The functions to do this are `org-ml-update-supercontents` and
`org-ml-update-supersection`. Both are only meant to edit the section underneath
the headlines in the buffer, and will not touch the headline itself. This takes
advantage of the new lazy evaluation system. These functions create an
abstraction over the contents of the headline that can be manipulated in a sane
way (see their docstrings for details).
There is one important caveat; if one changes the whitespace immediately after
the headline, this likely will change the :pre-blank property of the headline
which will require the headline to be rewritten (and resolved) which negates
this performance benefit. However, these functions are smart enough to figure
out when :pre-blank is changed.
### Other Considerations
Because lazy evaluation defers parsing the buffer, this assumes that the buffer
will not be edited in between the time the org-element syntax tree is created
and accessing any deferred properties. By extension it assumes the buffer is not
entirely destroyed (which is probably when dealing with temp buffers).
If one expects that the buffer will not retain state prior to accessing deferred
properties, use `org-element-properties-resolve` (which will resolve deferred
properties in place) or either `org-element-copy` or `org-ml-copy` which will
resolve deferred properties and copy the entire node (see more below).
## Node Copying
To maintain functional purity, all public-facing functions in `org-ml` that
modify nodes should return a copy. This way, modifications to the returned node
will not "go backward" to the original input node.
However, making copies can be slow. It also might be unnecessary within a
pipeline (usually with the threading macros `->` and `->>` from `dash.el`)
since the intermediate values are not bound to any variable, which leaves no
opportunity for accidental side-effect leakage.
To solve this use-case, `org-ml` has the following specialized threading macros:
- `org-ml->`
- `org-ml->>`
- `org-ml-->`
- `org-ml-some->`
- `org-ml-some->>`
- `org-ml-some-->`
These correspond to the sans-`org-ml` macros from `dash.el`
The `org-ml` versions will set `org-ml-use-impure` to t, which will turn off all
copying within the pipeline. (see `org-ml-copy` which is a thin wrapper around
`org-element-copy` with this switch built-in).
Note that the performance benefits of this are significant but modest (5-10%
depending on the complexity of the operation), and this comes with a significant
cost of reduced safety since it breaks the functional paradigm. Weight this
accordingly.
## Memoization
### Build Functions
Node building (functions like `org-ml-build-*`) is a pure operation (ie the
result only depends on the inputs). Furthermore, it is used in many places,
including internally to `org-ml` itself.
Therefore, memoizing these functions can produce significant performance gains.
To turn this on globally, set `org-ml-memoize-builders` to `t`. This will
memoize all leaf node builders by default (as it is assumed that any branch
nodes will be sufficiently complicated that most will be unique and therefore
miss the cache). For more fine-grained control over which nodes are memoized,
see `org-ml-memoize-builder-types`.
#### Shorthand Builders
There is an analogous optimization for 'shorthand' builders (functions like
`org-ml-build-*`) which use simplified inputs. These are controled by
`org-ml-memoize-shorthand-builders` and
`org-ml-memoize-shorthand-builder-types`. These will by default memoize all
shorthand builders except those for item and headline, for similar reasons to
above.
### Match Patterns
For all pattern-matching functions (eg `org-ml-match` and `org-ml-match-X`), the
`PATTERN` parameter is processed into a lambda function which computationally
carries out the pattern matching. If there are many calls using the same or a
few unique patterns, this lambda-generation overhead may be memoized by setting
`org-ml-memoize-match-patterns`. See this varible's documentation for details.
## Other potential optimizations
These are some ideas that may be implemented later depending on how much they
matter.
### Tree-based Diff Algorithm
It makes sense to only update the parts of a buffer that actually change.
However, this is complicated to do in practice.
Current versions of `org-ml` can use the Myers Diff Algorithm (the thing that
powers the `diff` program) to only edit the buffer contents that change (see
`org~ml-update`). This can have some speedup since buffer editing is somewhat
expensive. The obvious tradeoff is the algorithm itself needs to be performed
prior to the edit, and its complexity is quadratic.
The problem with this algorithm is that it only works on strings, thus the
org-element tree needs to be interpreted for this to be used. Not only is this
inherently expensive, it also negates any of the defferred property enhancements
that come with 9.7.
The (potential) solution is to implement a tree-based version of the Myers Diff
algorithm that works directly on the org-element tree. The result would be a
list of nodes to be inserted/deleted at a given position.
This would potentially have a huge benefit for deeply-nested edits, which often
happen in property drawers, logbooks, clocking entries, lists, etc.
### Lazy Evaluation for Supercontents Functions
The functions `org-ml-get/set/map-supercontents` (and related) all operate on a
complicated abstraction over a headline's section nodes. While this makes many
operations easy and convenient, it has the drawback of converting the entire
section even if only a small part needs to be changed. Making some parts of this
data structure lazy could make this faster.
This most obviously matters for cases where one wants to edit the planning or
property nodes of a headline which also has a massive logbook or a lot of
clocks. Currently the entire logbook, clocks, etc, will be processed, despite
a tiny unrelated node actually being updated.
# Development
For most stable results, make sure you have a working conda or mamba
installation. Conda is not strictly needed, but reproducible testing results are
not guaranteed.
Begin by creating a testing environment using the provided env* files (with the
desired version):
```
mamba env create -f env-XX.Y.yml
conda activate org-ml-XX.Y
```
Install all dependencies:
```
make install
```
Run all tests:
```
make unit
```
Run all tests with compilation:
```
make compile
```
To update a dependency, navidate to the `.emacs/XX.Y/straight/repos/<dep>`
directory (after installation) and run `git reset --hard <ref>` (after fetch if
needed) to pull the desired git state. Then run:
```
make freeze
```
Which will update `.emacs/XX.Y/straight/versions/default.el`
If any of the above make commands fail with: `undefined symbol:
malloc_set_state` or similar, try the following:
```
export LD_PRELOAD=/usr/lib/libc_malloc_debug.so
```
# Version History
See [changelog](CHANGELOG.md).
# Acknowledgments
- Ihor Radchenko: author or `org-element-ast.el`
- Nicolas Goaziou: author of `org-element.el`
- [@magnars](https://github.com/magnars):
[dash.el](https://github.com/magnars/dash.el) and
[s.el](https://github.com/magnars/s.el)
================================================
FILE: bench/org-ml-bench-fw.el
================================================
;;; org-ml-bench-fw.el --- Benchmark framework for org-ml -*- lexical-binding: t; -*-
;; Copyright (C) 2020 Free Software Foundation, Inc.
;; 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 <http://www.gnu.org/licenses/>.
;;; Commentary:
;; This framework provides a macro `org-ml-defbench' which is used to define
;; the default benchmarks as part of this library, and can also be used by end
;; users to define their own benchmarks.
;;; Code:
(require 's)
(require 'dash)
(require 'org-ml)
(defvar org-ml-benchmarks '()
"All defined benchmarks in the org-ml benchmark suite.")
(defun org-ml-bench-get-sys-info ()
(let ((cpumodel (if (eq system-type 'gnu/linux)
(->> (shell-command-to-string "lscpu | grep 'Model name:'")
(s-chop-prefix "Model name:")
(s-trim))
"unknown"))
(memtotal (if (eq system-type 'gnu/linux)
(->> (shell-command-to-string "grep MemTotal /proc/meminfo")
(s-chop-prefix "MemTotal:")
(s-trim))
"unknown"))
(org-ver (org-version))
(emacs-ver (s-replace "\n" "" (emacs-version))))
(s-join "\n"
(list
(format "CPU: %s" cpumodel)
(format "Total Memory: %s" memtotal)
(format "Org Version: %s" org-ver)
(format "Emacs Version: %s" emacs-ver)))))
(defmacro org-ml-bench-time-call (&rest body)
`(let ((start-time (float-time)))
,@body
(- (float-time) start-time)))
(defmacro org-ml-bench-with-org-file (repeated-pattern n &rest body)
(declare (indent 2))
`(let ((inhibit-message t))
(with-temp-buffer
(org-mode)
(insert (s-repeat ,n ,repeated-pattern))
(goto-char (point-min))
(garbage-collect)
(let ((time (org-ml-bench-time-call ,@body))
(res (buffer-string)))
(list res time)))))
(defun org-ml-bench-compare (repeated-pattern n form1 form2)
(declare (indent 2))
`(-let (((res1 time1) (org-ml-bench-with-org-file ,repeated-pattern ,n ,form1))
((res2 time2) (org-ml-bench-with-org-file ,repeated-pattern ,n ,form2)))
(unless (equal res1 res2)
(print "WARNING: forms produced different buffer strings")
(print (cadr (s-lines res1)))
(print (cadr (s-lines res2))))
(list time1 time2)))
(defun org-ml-bench-format-result-row (title n time1 time2)
(format "| %-40s | %6s | %10.5f | %10.5f | %10.2f |" title n time1 time2
(/ time2 time1)))
(defmacro org-ml-defbench (title n pattern form1 form2)
"Define a benchmark.
TITLE is a short string that will be used to identify the
benchmark (uniqueness isn't enforced but makes sense). FORM1 and
FORM2 are the two forms to be compared; by convention the first
is a function composed of built-in org commands and the second is
one composed of org-ml commands. FORM1 and FORM2 will be applied
to a buffer with PATTERN repeated N times. Note the both forms
will only be called once and thus must contain the code for
iterating across PATTERN as desired.
Calling `org-ml-bench-run' will execute all benchmarks in the
order they are defined with this macro."
(declare (indent 2))
(let ((p (format "%s\n" (if (listp pattern)
(s-join "\n" (eval pattern))
pattern))))
`(add-to-list 'org-ml-benchmarks
(lambda ()
(print (format "Starting benchmark: %s" ,title))
(-let (((time1 time2)
,(org-ml-bench-compare p n form1 form2)))
(org-ml-bench-format-result-row ,title ,n time1 time2))))))
(defun org-ml-bench-run ()
"Run and print all defined benchmarks."
(let ((test-rows (--map (funcall it) (reverse org-ml-benchmarks))))
(print
(s-join "\n"
(append
(list
""
(org-ml-bench-get-sys-info)
""
(format "| %-40s | %6s | %10s | %10s | %10s |"
"Test name" "N" "Native" "org-ml" "X Increase"))
test-rows
(list ""))))))
(provide 'org-ml-bench-fw)
;;; org-ml-bench-fw.el ends here
================================================
FILE: bench/org-ml-benchmarks.el
================================================
;;; org-ml-benchmarks.el --- Benchmarks for org-ml -*- lexical-binding: t; -*-
;; Copyright (C) 2020 Free Software Foundation, Inc.
;; 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 <http://www.gnu.org/licenses/>.
;;; Commentary:
;;; Code:
(require 'org-ml-bench-fw)
(org-ml-defbench "read TODO" 10000
"* TODO headline"
(let ((next t))
(while next
(org-get-todo-state)
(setq next (outline-next-heading))))
(->> (org-ml-parse-headlines 'all)
(--map (org-ml-get-property :todo-keyword it))))
(org-ml-defbench "read SCHEDULED epoch time" 2500
(list "* TODO headline"
"SCHEDULED: <2020-01-01 Tue>")
(let ((next t))
(while next
(org-2ft (org-entry-get (point) "SCHEDULED"))
(setq next (outline-next-heading))))
(--each (org-ml-parse-headlines 'all)
(->> (plist-get (org-ml-headline-get-planning it) :scheduled)
(org-ml-timelist-to-unixtime))))
(org-ml-defbench "TODO -> DONE" 1000
"* TODO headline"
(let ((org-log-done 'time)
(org-todo-keywords '((sequence "TODO" "|" "DONE")))
(org-adapt-indentation nil)
(next t))
(while next
(org-todo 'done)
(setq next (outline-next-heading))))
(let ((planning `(:closed ,(org-ml-unixtime-to-timelist t (float-time)))))
(org-ml-wrap-impure
(org-ml-update-headlines* 'all
(->> (org-ml-set-property :todo-keyword "DONE" it)
(org-ml-headline-set-planning planning))))))
(org-ml-defbench "demote headlines" 2500
"* headline"
(let ((org-adapt-indentation nil)
(next t))
(while next
(org-do-demote)
(setq next (outline-next-heading))))
(org-ml-wrap-impure
(org-ml-update-headlines* 'all
(org-ml-shift-property :level 1 it))))
(org-ml-defbench "demote subtrees" 2500
(list "* headline"
"** subheadline")
(let ((org-adapt-indentation nil)
(next t))
(while next
(org-demote)
(setq next (outline-next-heading))))
(org-ml-wrap-impure
(org-ml-update-subtrees* 'all
(org-ml--headline-subtree-shift-level 1 it))))
(org-ml-defbench "tag headline" 1000
"* headline"
(let ((next t))
(while next
(org-set-tags '("A" "B" "C"))
(setq next (outline-next-heading))))
(org-ml-wrap-impure
(org-ml-update-headlines* 'all
(org-ml-set-property :tags '("A" "B" "C") it))))
;; TODO a better test for this would be to put a logbook underneath the
;; planning ts since in that case we need to also parse the logbook
(org-ml-defbench "schedule headline" 1000
(list "* headline")
;; ":LOGGING:"
;; "- Note taken on [2024-08-07 Wed 20:07] \\"
;; "thingy"
;; ":END:")
(let ((org-adapt-indentation nil)
(next t))
(while next
(org-schedule nil "2000-01-01")
(setq next (outline-next-heading))))
(let ((pl '(:scheduled (2000 1 1))))
(org-ml-wrap-impure
(org-ml-update-supercontents* nil 'all
(org-ml-supercontents-set-planning pl it)))))
(org-ml-defbench "schedule headline (memoized)" 1000
(list "* headline")
;; ":LOGGING:"
;; "- Note taken on [2024-08-07 Wed 20:07] \\"
;; "thingy"
;; ":END:")
(let ((org-adapt-indentation nil)
(next t))
(while next
(org-schedule nil "2000-01-01")
(setq next (outline-next-heading))))
(let ((pl '(:scheduled (2000 1 1))))
(let ((org-ml-memoize-shorthand-builders t))
(org-ml-wrap-impure
(org-ml-update-supercontents* nil 'all
(org-ml-supercontents-set-planning pl it))))))
(org-ml-defbench "reschedule headline" 1000
(list "* headline"
"SCHEDULED: <2020-01-01 Wed>")
(let ((org-adapt-indentation nil)
(next t))
(while next
(->> (org-get-scheduled-time (point))
(float-time)
;; shift up one day
(+ (* 24 60 60))
(format-time-string "%Y-%m-%d")
(org-schedule nil))
(setq next (outline-next-heading))))
(org-ml-wrap-impure
(org-ml-update-supercontents* nil 'all
(org-ml-supercontents-set-planning
(list :scheduled
(org-ml-timelist-shift
1 'day
(plist-get (org-ml-supercontents-get-planning it) :scheduled)))
it))))
(org-ml-defbench "reschedule headline (memoized)" 1000
(list "* headline"
"SCHEDULED: <2020-01-01 Wed>")
(let ((org-adapt-indentation nil)
(next t))
(while next
(->> (org-get-scheduled-time (point))
(float-time)
;; shift up one day
(+ (* 24 60 60))
(format-time-string "%Y-%m-%d")
(org-schedule nil))
(setq next (outline-next-heading))))
(org-ml-wrap-impure
(let ((org-ml-memoize-shorthand-builders t))
(org-ml-update-supercontents* nil 'all
(org-ml-supercontents-set-planning
(list :scheduled
(org-ml-timelist-shift
1 'day
(plist-get (org-ml-supercontents-get-planning it) :scheduled)))
it)))))
(org-ml-defbench "set headline effort" 1000
"* headline"
(let ((org-adapt-indentation nil)
(next t))
(while next
(org-set-property "Effort" "0:05")
(setq next (outline-next-heading))))
(org-ml-wrap-impure
(org-ml-update-supercontents* nil 'all
(org-ml-supercontents-set-node-properties '(("Effort" "0:05")) it))))
(org-ml-defbench "set headline effort (memoized)" 1000
"* headline"
(let ((org-adapt-indentation nil)
(next t))
(while next
(org-set-property "Effort" "0:05")
(setq next (outline-next-heading))))
(org-ml-wrap-impure
(let ((org-ml-memoize-shorthand-builders t))
(org-ml-update-supercontents* nil 'all
(org-ml-supercontents-set-node-properties '(("Effort" "0:05")) it)))))
(org-ml-defbench "insert headline text" 2500
"* headline"
(let ((org-adapt-indentation nil)
(next t))
(while next
(save-excursion
(org-end-of-subtree)
(insert "\n~some text~"))
(setq next (outline-next-heading))))
(org-ml-wrap-impure
(org-ml-update-supercontents* nil 'all
(-> (org-ml-build-paragraph! "~some text~")
(list)
(org-ml-supercontents-set-contents it)))))
(org-ml-defbench "insert headline text (memoized)" 2500
"* headline"
(let ((org-adapt-indentation nil)
(next t))
(while next
(save-excursion
(org-end-of-subtree)
(insert "\n~some text~"))
(setq next (outline-next-heading))))
(org-ml-wrap-impure
(let ((org-ml-memoize-shorthand-builders t))
(org-ml-update-supercontents* nil 'all
(-> (org-ml-build-paragraph! "~some text~")
(list)
(org-ml-supercontents-set-contents it))))))
(org-ml-defbench "set checkboxes" 1000
(list "* headline [0/0]"
"- [ ] one"
"- [ ] two")
(let ((org-adapt-indentation nil)
(next t))
(while next
(org-toggle-checkbox)
(setq next (outline-next-heading))))
(let ((org-ml-memoize-match-patterns 'compiled))
(org-ml-update-headlines* 'all
(org-ml->> (org-ml-match-map '(section plain-list item) #'org-ml-item-toggle-checkbox it)
(org-ml-headline-update-item-statistics)))))
(org-ml-defbench "set headline effort/TODO/scheduled" 1000
"* headline"
(let ((org-log-done 'time)
(org-todo-keywords '((sequence "TODO" "|" "DONE")))
(org-adapt-indentation nil)
(next t))
(while next
(org-schedule nil "2000-01-01")
(org-set-property "Effort" "0:05")
(org-todo 'todo)
(setq next (outline-next-heading))))
(let ((pl '(:scheduled (2000 1 1))))
(let ((org-ml-memoize-shorthand-builders t))
(org-ml-update-headlines* 'all
(org-ml->> (org-ml-set-property :todo-keyword "TODO" it)
(org-ml-headline-set-node-property "Effort" "0:05")
(org-ml-headline-set-planning pl))))))
(provide 'org-ml-benchmarks)
;;; org-ml-benchmarks.el ends here
================================================
FILE: dev/org-ml-cookbook.el
================================================
;;; org-ml-cookbook.el --- Common patterns for org.el's -*- lexical-binding: t -*-
;; Copyright (C) 2015 Free Software Foundation, Inc.
;; 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 <http://www.gnu.org/licenses/>.
;;; Commentary:
;;; Code:
(require 's)
(require 'dash)
(require 'org-ml)
(defrecipe "Adding created time"
"This will add a property called CREATED with a timestamp (which could be modified to hold the current time).."
("* headine")
(let ((ts (org-ml-to-string (org-ml-build-timestamp! '(2020 1 1 0 0)))))
(->> (org-ml-parse-this-headline)
(org-ml-headline-set-node-property "CREATED" ts)
(org-ml-to-string)))
=> (:result "* headline"
":PROPERTIES:"
":CREATED: [2020-01-01 Wed 00:00]"
":END:"))
(provide 'org-ml-cookbook)
;;; org-ml-cookbook.el ends here
================================================
FILE: dev/org-ml-docs.el
================================================
;;; org-ml-docs.el --- Extract org-ml's docs -*- lexical-binding: t; -*-
;; Copyright (C) 2015 Free Software Foundation, Inc.
;; 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 <http://www.gnu.org/licenses/>.
;;; Commentary:
;;; Code:
(require 's)
(require 'dash)
(require 'help-fns)
(require 'package)
(setq text-quoting-style 'grave)
(defvar org-ml-dev-examples-list '())
(defvar org-ml-dev-recipe-list '())
(defconst org-ml-elem--fill-column 80)
(defun org-ml-get-package-version ()
"Get version of om package."
(with-current-buffer (find-file-noselect "org-ml.el")
(mapconcat 'number-to-string (package-desc-version (package-buffer-info)) version-separator)))
(defun format-multiline (s &optional ident)
(let ((ident (or ident 2)))
(cl-labels
((go
(x i)
(let ((test (format "%S" x)))
(if (< (+ (length test) i) 80) test
(if (not (consp x)) test
(-let* (((fun . rest) x)
(sfun (format "%S" fun))
(ws (concat "\n" (s-repeat i " ")))
(srest (--map (go it (+ i ident)) rest)))
(if (null srest) test
(-let (((r . rs) srest))
(if (< (+ (length sfun) (length r) 2) 80)
(format "(%S %s)" fun (s-join ws srest))
(format "(%s)" (s-join ws `(,sfun ,r ,@rs))))))))))))
(go s ident))))
(defun format-actual (actual)
(format-multiline actual))
(defun format-expected (sym expected)
(let* ((s (s-lines (format "%S" expected)))
(header (format " ;; %S %s" sym (car s)))
(rest (--map (if (stringp expected) (s-prepend " ; " it)
(s-prepend " ; " it))
(-drop 1 s))))
(s-join "\n" (cons header rest))))
(defun example-to-string (example)
(-let* (((actual sym expected) example)
(expected
(if (eq (and (listp expected) (car expected)) :result)
(s-join "\n" (cdr expected))
expected))
(actual (format-actual actual))
(comment
(cond
((eq sym '=>) (format-expected sym expected))
;; ((eq sym '~>) (format-expected sym expected))
((eq sym '$>) (concat " ;; Output these buffer contents\n"
(format-expected sym expected)))
((eq sym '!!>) (format "Error"))
(t (error "Invalid test case: %s" `(,actual ,sym ,expected))))))
(--> comment
(format "%s\n%s\n" actual it)
(replace-regexp-in-string "\\\\\\?" "?" it)
;; (replace-regexp-in-string "\n" "\\n" it t t)
;; (replace-regexp-in-string "\t" "\\t" it t t)
(replace-regexp-in-string "\r" "\\r" it t t))))
;; (format "```el\n%s\n```\n" it))))
(defun docs--signature (function)
"Given FUNCTION (a symbol), return its argument list.
FUNCTION may reference an elisp function, alias, macro or a subr."
(let* ((function-value (indirect-function function))
(is-alias (not (eq function-value (symbol-function function))))
;; if FUNCTION isn't an alias, function-symbol is simply FUNCTION
(function-symbol function))
(when is-alias
;; find the last symbol in the alias chain
(while (symbolp (symbol-function function-symbol))
(setq function-symbol (symbol-function function-symbol))))
(or
(-some->> (help-split-fundoc (documentation function-value)
function-symbol)
(car)
(downcase)
(read)
(cdr))
(help-function-arglist function-symbol))))
;; (if (subrp function-value)
;; ;; read the docstring to find the signature for subrs
;; (let* ((docstring-args (car (help-split-fundoc
;; (documentation function-value)
;; function-symbol)))
;; (fun-with-args (read (downcase docstring-args))))
;; (cdr fun-with-args))
;; ;; otherwise get the signature directly
;; (help-function-arglist function-symbol))))
(defun format-doc (cmd)
;; remove extra signature for cl-defun org-ml-dev-examples-list
;; TODO this is hacky but it works
(let ((doc (documentation cmd)))
(unless doc (error "No docstring set for %s" cmd))
(if (not (s-matches? "(fn .*)" doc)) doc
(->> (s-lines doc) (-drop-last 2) (s-join "\n")))))
(defun filter-hidden (args)
(->> (--split-when (eq it :end-hidden) args)
(--mapcat (--take-while (not (eq it :begin-hidden)) it))))
(defmacro defexamples (cmd &rest examples)
`(add-to-list 'org-ml-dev-examples-list
(list
',cmd
(docs--signature ',cmd)
(format-doc ',cmd)
(->> ',examples
(filter-hidden)
(-partition 3)
(-map 'example-to-string)))))
(defun format-buffer-contents (list)
(->> (--map (format "; %s" it) list)
(s-join "\n")
(format ";; Given the following contents:\n%s\n")))
(defmacro defexamples-content (cmd docstring &rest args)
`(cl-flet
((formatted-string?
(list)
(memq (and (listp list) (car list)) '(:buffer :comment)))
(format-content
(list)
(->> (car list)
(-drop 1)
(format-buffer-contents)))
;; (--map (format "; %s" it))
;; (s-join "\n")
;; (format ";; Given the following contents:\n%s\n")))
(format-comment
(list)
(let ((comment (->> (car list)
(-drop 1)
(s-join " ")
(format ";; %s"))))
(with-temp-buffer
(emacs-lisp-mode)
(insert comment)
(let ((fill-column org-ml-elem--fill-column))
(fill-paragraph))
(buffer-string)))))
(let* ((doc (or ,docstring (format-doc ',cmd)))
(example
(->> (filter-hidden ',args)
(-partition-by #'formatted-string?)
(--map (cond
((eq :comment (car (car it)))
(format-comment it))
((eq :buffer (car (car it)))
(format-content it))
(t (-some->>
(-partition 3 it)
(-map #'example-to-string)
(s-join "\n"))))))))
(add-to-list 'org-ml-dev-examples-list (list ',cmd
(docs--signature ',cmd)
doc
(or example '("no examples :(")))))))
(defmacro defrecipe (header description contents form operator result)
`(let ((example (example-to-string (list ',form ',operator ',result)))
(contents* (format-buffer-contents ',contents)))
(add-to-list 'org-ml-dev-recipe-list
(format "## %s\n\n%s\n\n```el\n%s\n%s```\n"
,header ,description contents* example))))
(defmacro def-example-subgroup (group desc &rest examples)
`(progn
;; (add-to-list 'org-ml-dev-examples-list ,(concat "### " group))
(setq org-ml-dev-examples-list (cons ,(concat "### " group) org-ml-dev-examples-list))
(when ,desc
;; (add-to-list 'org-ml-dev-examples-list ,desc))
(setq org-ml-dev-examples-list (cons ,desc org-ml-dev-examples-list)))
,@examples))
(defmacro def-example-group (group desc &rest examples)
`(progn
;; (add-to-list 'org-ml-dev-examples-list ,(concat "## " group))
(setq org-ml-dev-examples-list (cons ,(concat "## " group) org-ml-dev-examples-list))
(when ,desc
;; (add-to-list 'org-ml-dev-examples-list ,desc))
(setq org-ml-dev-examples-list (cons ,desc org-ml-dev-examples-list)))
,@examples))
(defun format-link (string-name)
(-let* ((name (intern string-name))
((_ signature _ _) (assoc name org-ml-dev-examples-list)))
(if signature
(format "[`%s`](#%s)" name (github-id name signature))
(format "`%s`" name))))
(defun format-docstring-forms (docstring)
(cl-labels
((find-matching-right
(p)
;; return point of matching ")" or nil if not found
(ignore-errors
(save-excursion
(goto-char p)
(forward-sexp)
(1- (point)))))
(has-leading-function?
(string)
(->> (s-replace-regexp "(+" "" string)
(s-split " ")
(car)
(intern)
(fboundp)))
(has-all-cap-syms?
(string)
(->> (s-replace-regexp "[().,]" "" string)
(s-replace "[" "")
(s-replace "]" "")
(s-split " ")
(--remove (equal it ""))
(--all? (or (member it '("t" "nil" "|" "*" "?"))
(s-matches? "^[A-Z0-9\\-]+$" it)
(s-matches? "^\\(:\\|&\\)[a-z0-9-]+$" it)))))
(is-form?
(string)
(or ;; (has-leading-function? string)
(has-all-cap-syms? string))))
(let (case-fold-search)
(with-temp-buffer
(insert docstring)
(goto-char (point-min))
(while (and (< (point) (point-max))
(search-forward "(" nil t))
(-when-let (e (find-matching-right (1- (point))))
(when (is-form? (buffer-substring (point) e))
(downcase-region (point) e)
(goto-char (1- (point)))
(insert "`")
(goto-char (+ 2 e))
(insert "`")))
(unless (= (point) (point-max))
(forward-char)))
(buffer-string)))))
(defun format-docstring-args (signature docstring)
(let ((sig-args (->> signature
(--remove (memq it '(&optional &key &rest)))
(--map (if (consp it) (car it) it))
(-map #'symbol-name))))
(cl-flet
((quote-and-downcase
(string)
;; hack to work around % not being part of word boundaries
(let ((s (s-chop-suffix "%" (downcase string))))
(if (member s sig-args) (format "**`%s`**" s)
(format "`%s`" s)))))
(replace-regexp-in-string
"\\b\\(?3:[A-Z][A-Z-]*[0-9*]*\\)\\(\\*\\|%\\|\\b\\)"
;; "[^A-Z0-9-]\\([A-Z0-9-]+\\)[^A-Z0-9-]"
#'quote-and-downcase docstring t nil 3))))
(defun format-docstring-backquoted (docstring)
(cl-flet
((unquote-and-link
(string)
(format-link (substring string 1 -1))))
(replace-regexp-in-string "`\\([^ \n]+\\)'" #'unquote-and-link docstring t)))
(defun format-docstring-indent (docstring)
(replace-regexp-in-string "^ " " " docstring))
(defun format-docstring-strings (docstring)
(cl-flet
((quote-string
(string)
(format "`%s`" string)))
(s-replace-regexp "\"[[:ascii:]]*?\"" #'quote-string docstring)))
(defun format-docstring (signature docstring)
(let (case-fold-search)
(->> docstring
(format-docstring-strings)
(format-docstring-forms)
(format-docstring-args signature)
(format-docstring-backquoted)
(format-docstring-indent))))
(defun function-to-md (function)
(if (stringp function)
(concat "\n" (s-replace "### " "### " function) "\n")
(-let [(command-name signature docstring examples) function]
(unless docstring
(error "No docstring supplied for %s" command-name))
(format "#### %s `%S`\n\n%s\n\n```el\n%s\n```\n"
;; (format "### %s `%s`\n\n%s\n\n%s"
command-name
signature
(format-docstring signature docstring)
;; (mapconcat 'identity (-take 3 examples) "\n")))))
(mapconcat 'identity examples "\n")))))
;; (defun docs--chop-prefix (prefix s)
;; "Remove PREFIX if it is at the start of S."
;; (let ((pos (length prefix)))
;; (if (and (>= (length s) (length prefix))
;; (string= prefix (substring s 0 pos)))
;; (substring s pos)
;; s)))
;; (defun docs--chop-suffix (suffix s)
;; "Remove SUFFIX if it is at end of S."
;; (let ((pos (- (length suffix))))
;; (if (and (>= (length s) (length suffix))
;; (string= suffix (substring s pos)))
;; (substring s 0 pos)
;; s)))
(defun github-id (command-name signature)
(->> (format "%S-%S" command-name signature)
(s-downcase)
(s-replace-regexp "[^a-zA-Z0-9- ]+" "")
(s-replace " " "-")))
(defun s-replace (old new s)
"Replace OLD with NEW in S."
(replace-regexp-in-string (regexp-quote old) new s t t))
(defun function-summary (function)
(if (stringp function)
(concat "\n" function "\n")
(let ((command-name (car function))
(signature (cadr function)))
(format "* [%s](#%s) `%S`" command-name (github-id command-name signature) signature))))
(defun simplify-quotes ()
(goto-char (point-min))
(while (search-forward "(quote nil)" nil t)
(replace-match "'()"))
(goto-char (point-min))
(while (search-forward "(quote " nil t)
(forward-char -7)
(let ((p (point)))
(forward-sexp 1)
(delete-char -1)
(goto-char p)
(delete-char 7)
(insert "'"))))
(defun goto-and-remove (s)
(goto-char (point-min))
(search-forward s)
(delete-char (- (length s))))
(defun goto-and-replace-all (s replacement)
(while (progn (goto-char (point-min)) (search-forward s nil t))
(delete-char (- (length s)))
(insert replacement)))
(defun create-cookbook ()
(with-temp-file "./docs/cookbook.md"
(insert "# org-ml cookbook\n\n")
(insert
(concat "The following are a list of common use cases and formulations"
"for `org-ml`. If a function is not available straight from the"
"API it may be here.\n\n"))
(insert (s-join "\n" org-ml-dev-recipe-list))))
(defun create-api-ref ()
(let ((org-ml-dev-examples-list (nreverse org-ml-dev-examples-list)))
(with-temp-file "./docs/api-reference.md"
(insert "# API Reference\n")
(insert (mapconcat 'function-summary org-ml-dev-examples-list "\n"))
(insert (mapconcat 'function-to-md org-ml-dev-examples-list "\n"))
(insert (format "Version: %s" (org-ml-get-package-version)))
(simplify-quotes))))
(defun create-docs-files ()
(create-cookbook)
(create-api-ref))
;; require the examples
(require 'org-ml-examples)
(require 'org-ml-cookbook)
;; tell user how many functions have no examples
(defconst org-ml-dev-defined-names nil
"Alist of all functions/macros defined in `org-ml.el'.
The two cells in the alist are 'private' and 'public'.")
(mapatoms
(lambda (x)
(when (and (fboundp x) (s-starts-with-p "org-ml-" (symbol-name x)))
(push x org-ml-dev-defined-names))))
(setq org-ml-dev-defined-names
(--group-by
(if (s-starts-with-p "org-ml--" (symbol-name it)) 'private 'public)
org-ml-dev-defined-names))
(let ((public-syms (alist-get 'public org-ml-dev-defined-names))
(example-syms (->> (-remove #'stringp org-ml-dev-examples-list)
(-map #'car))))
(-some->> (-difference public-syms example-syms)
(-map #'symbol-name)
(--remove (s-ends-with? "*" it))
(--remove (s-starts-with? "org-ml-update-this-" it))
(--remove (s-starts-with? "org-ml-parse-this-" it))
(--map (format " %s" it))
(s-join "\n")
(format "The following functions don't have examples:\n%s")
(print)))
(provide 'org-ml-docs)
;;; org-ml-docs.el ends here
================================================
FILE: dev/org-ml-examples.el
================================================
;;; org-ml-examples.el --- Examples for org.el's API -*- lexical-binding: t -*-
;; Copyright (C) 2015 Free Software Foundation, Inc.
;; 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 <http://www.gnu.org/licenses/>.
;;; Commentary:
;;; Code:
(require 's)
(require 'dash)
(require 'org-ml)
(def-example-group "String Conversion"
"Convert nodes to strings."
;; these are more thoroughly tested in `org-ml-test-internal.el'
(defexamples org-ml-to-string
(org-ml-to-string
'(bold
(:begin 1 :end 5 :parent nil :post-blank 0 :post-affiliated nil)
"text"))
=> "*text*"
(org-ml-to-string
'(bold
(:begin 1 :end 5 :parent nil :post-blank 3 :post-affiliated nil)
"text"))
=> "*text* "
(org-ml-to-string nil) => "")
(defexamples org-ml-to-trimmed-string
(org-ml-to-trimmed-string
'(bold
(:begin 1 :end 5 :parent nil :post-blank 0 :post-affiliated nil)
"text"))
=> "*text*"
(org-ml-to-trimmed-string
'(bold
(:begin 1 :end 5 :parent nil :post-blank 3 :post-affiliated nil)
"text"))
=> "*text*"
(org-ml-to-trimmed-string nil) => "")
(defexamples org-ml-from-string
(->> (org-ml-from-string 'bold "*text*")
(org-ml-get-type))
=> 'bold
(->> (org-ml-from-string 'bold "*text*")
(org-ml-get-property :begin))
=> 1
(->> (org-ml-from-string 'bold "*text*")
(org-ml-get-property :end))
=> 7
(->> (org-ml-from-string 'bold "*text*")
(org-ml-get-property :post-blank))
=> 0
(->> (org-ml-from-string 'bold "*text*")
(org-ml-get-property :contents-begin))
=> 2
(->> (org-ml-from-string 'bold "*text*")
(org-ml-get-property :contents-end))
=> 6
(org-ml-from-string 'italic "*text*")
=> nil))
(def-example-group "Buffer Parsing"
"Parse buffers to trees."
;; these are more thoroughly tested in `org-ml-dev-test.el'
(defexamples-content org-ml-parse-this-buffer
nil
(:buffer "text")
(->> (org-ml-parse-this-buffer)
(org-ml-get-property :begin))
=> 1
(->> (org-ml-parse-this-buffer)
(org-ml-get-property :end))
=> 5)
(defexamples-content org-ml-parse-object-at
nil
(:buffer "*text*")
(->> (org-ml-parse-object-at 1)
(car))
=> 'bold
(:buffer "[2019-01-01 Tue]")
(->> (org-ml-parse-object-at 1)
(car))
=> 'timestamp
(:buffer "- notme")
(:comment "Return nil when parsing an element")
(org-ml-parse-object-at 1)
=> nil)
(defexamples-content org-ml-parse-element-at
nil
(:buffer "#+call: ktulu()")
(->> (org-ml-parse-element-at 1)
(car))
=> 'babel-call
(:buffer "- plain-list")
(:comment "Give the plain-list, not the item for this function")
(->> (org-ml-parse-element-at 1)
(car))
=> 'plain-list
(:buffer "| R | A |"
"| G | E |")
(:comment "Return a table, not the table-row for this function")
(->> (org-ml-parse-element-at 1)
(car))
=> 'table)
(defexamples-content org-ml-parse-table-row-at
nil
(:buffer "| bow | stroke |"
"|-----+--------|"
"| wob | ekorts |")
(:comment "Return the row itself")
(->> (org-ml-parse-table-row-at 1)
(car))
=> 'table-row
(->> (org-ml-parse-table-row-at 20)
(car))
=> 'table-row
(->> (org-ml-parse-table-row-at 40)
(car))
=> 'table-row
(:comment "Also return the row when not at beginning of line")
(->> (org-ml-parse-table-row-at 5)
(car))
=> 'table-row
(:buffer "- bow and arrow choke")
(:comment "Return nil if not a table-row")
(->> (org-ml-parse-table-row-at 1)
(car))
=> nil)
(defexamples-content org-ml-parse-headline-at
nil
(:buffer "* headline")
(:comment "Return the headline itself")
(->> (org-ml-parse-headline-at 1)
(org-ml-to-trimmed-string))
=> "* headline"
(:buffer "* headline"
"section crap")
(:comment "Return headline and section")
(->> (org-ml-parse-headline-at 1)
(org-ml-to-trimmed-string))
=> (:result "* headline"
"section crap")
(:comment "Return headline when point is in the section")
(->> (org-ml-parse-headline-at 12)
(org-ml-to-trimmed-string))
=> (:result "* headline"
"section crap")
(:buffer "* headline"
"section crap"
"** not parsed")
(:comment "Don't parse any subheadlines")
(->> (org-ml-parse-headline-at 1)
(org-ml-to-trimmed-string))
=> (:result "* headline"
"section crap")
(:buffer "nothing nowhere")
(:comment "Return nil if not under a headline")
(->> (org-ml-parse-headline-at 1)
(org-ml-to-trimmed-string))
=> "")
(defexamples-content org-ml-parse-subtree-at
nil
(:buffer "* headline")
(:comment "Return the headline itself")
(->> (org-ml-parse-subtree-at 1)
(org-ml-to-trimmed-string))
=> "* headline"
(:buffer "* headline"
"section crap")
(:comment "Return headline and section")
(->> (org-ml-parse-subtree-at 1)
(org-ml-to-trimmed-string))
=> (:result "* headline"
"section crap")
(:comment "Return headline when point is in the section")
(->> (org-ml-parse-subtree-at 12)
(org-ml-to-trimmed-string))
=> (:result "* headline"
"section crap")
(:buffer "* headline"
"section crap"
"** parsed")
(:comment "Return all the subheadlines")
(->> (org-ml-parse-subtree-at 1)
(org-ml-to-trimmed-string))
=> (:result "* headline"
"section crap"
"** parsed")
(:buffer "nothing nowhere")
(:comment "Return nil if not under a headline")
(->> (org-ml-parse-subtree-at 1)
(org-ml-to-trimmed-string))
=> "")
(defexamples-content org-ml-parse-item-at
nil
(:buffer "- item")
(:comment "Return the item itself")
(->> (org-ml-parse-item-at 1)
(org-ml-to-trimmed-string))
=> "- item"
(:comment "Also return the item when not at beginning of line")
(->> (org-ml-parse-item-at 5)
(org-ml-to-trimmed-string))
=> "- item"
(:buffer "- item"
" - item 2")
(:comment "Return item and its subitems")
(->> (org-ml-parse-item-at 1)
(org-ml-to-trimmed-string))
=> (:result "- item"
" - item 2")
(:buffer "* not item")
(:comment "Return nil if not an item")
(->> (org-ml-parse-item-at 1)
(org-ml-to-trimmed-string))
=> "")
(defexamples-content org-ml-parse-section-at
nil
(:buffer "over headline"
"* headline"
"under headline")
(:comment "Return the section above the headline")
(->> (org-ml-parse-section-at 1)
(org-ml-to-trimmed-string))
=> "over headline"
(:comment "Return the section under headline")
(->> (org-ml-parse-section-at 25)
(org-ml-to-trimmed-string))
=> "under headline"
(:buffer "* headline"
"** subheadline")
(:comment "Return nil if no section under headline")
(->> (org-ml-parse-section-at 1)
(org-ml-to-trimmed-string))
=> ""
(:buffer "")
(:comment "Return nil if no section at all")
(->> (org-ml-parse-section-at 1)
(org-ml-to-trimmed-string))
=> "")
(defexamples-content org-ml-parse-this-toplevel-section
nil
(:buffer "over headline"
"* headline"
"under headline")
(->> (org-ml-parse-this-toplevel-section)
(org-ml-to-trimmed-string))
=> "over headline"
(:buffer "* headline"
"under headline")
(->> (org-ml-parse-this-toplevel-section)
(org-ml-to-trimmed-string))
=> "")
(defexamples-content org-ml-this-buffer-has-headlines
nil
(:buffer "not headline"
"* headline")
(org-ml-this-buffer-has-headlines)
=> t
(:buffer "not headline")
(org-ml-this-buffer-has-headlines)
=> nil)
(defexamples-content org-ml-parse-headlines
nil
(:buffer "not headline"
"* one"
"* two"
"* three")
(->> (org-ml-parse-headlines 'all)
(-map #'org-ml-to-string)
(s-join ""))
=> (:result "* one"
"* two"
"* three"
"")
(:buffer "not headline")
(->> (org-ml-parse-headlines 'all)
(-map #'org-ml-to-string)
(s-join ""))
=> ""
(:buffer "not headline"
"* one"
"** two"
"*** three")
(->> (org-ml-parse-headlines 'all)
(-map #'org-ml-to-trimmed-string))
=> '("* one\n** two\n*** three" "** two\n*** three" "*** three")
(:buffer "not headline"
"*ignore this*"
"* one"
"* two"
"* three")
(->> (org-ml-parse-headlines 0)
(-map #'org-ml-to-string)
(s-join ""))
=> "* one\n"
(->> (org-ml-parse-headlines '(0 1))
(-map #'org-ml-to-string)
(s-join ""))
=> (:result "* one"
"* two\n")
(->> (org-ml-parse-headlines [23 38])
(-map #'org-ml-to-string)
(s-join ""))
=> (:result "* one"
"* two\n"))
(defexamples-content org-ml-parse-subtrees
nil
(:buffer "not headline"
"* one"
"** _one"
"* two"
"** _two"
"* three"
"** _three")
(->> (org-ml-parse-subtrees 'all)
(-map #'org-ml-to-string)
(s-join ""))
=> (:result "* one"
"** _one"
"* two"
"** _two"
"* three"
"** _three\n")
(:buffer "not headline")
(->> (org-ml-parse-subtrees 'all)
(-map #'org-ml-to-string)
(s-join ""))
=> ""
(:buffer "not headline"
"* one"
"** _one"
"* two"
"** _two"
"* three"
"** _three")
(->> (org-ml-parse-subtrees 0)
(-map #'org-ml-to-string)
(s-join ""))
=> (:result "* one"
"** _one\n")
(->> (org-ml-parse-subtrees '(0 1))
(-map #'org-ml-to-string)
(s-join ""))
=> (:result "* one"
"** _one"
"* two"
"** _two\n")
(->> (org-ml-parse-subtrees [10 30])
(-map #'org-ml-to-string)
(s-join ""))
=> (:result "* one"
"** _one"
"* two"
"** _two\n")))
(def-example-group "Building"
"Build new nodes."
(def-example-subgroup "Leaf Object Nodes"
nil
(defexamples org-ml-build-code
(->> (org-ml-build-code "text")
(org-ml-to-string))
=> "~text~")
(defexamples org-ml-build-entity
(->> (org-ml-build-entity "gamma")
(org-ml-to-string))
=> "\\gamma")
(defexamples org-ml-build-export-snippet
(->> (org-ml-build-export-snippet "back" "value")
(org-ml-to-string))
=> "@@back:value@@")
(defexamples org-ml-build-inline-babel-call
(->> (org-ml-build-inline-babel-call "name")
(org-ml-to-string))
=> "call_name()"
(->> (org-ml-build-inline-babel-call "name" :arguments '("n=4"))
(org-ml-to-string))
=> "call_name(n=4)"
(->> (org-ml-build-inline-babel-call "name" :inside-header '(:key val))
(org-ml-to-string))
=> "call_name[:key val]()"
(->> (org-ml-build-inline-babel-call "name" :end-header '(:key val))
(org-ml-to-string))
=> "call_name()[:key val]")
(defexamples org-ml-build-inline-src-block
(->> (org-ml-build-inline-src-block "lang")
(org-ml-to-string))
=> "src_lang{}"
(->> (org-ml-build-inline-src-block "lang" :value "value")
(org-ml-to-string))
=> "src_lang{value}"
(->> (org-ml-build-inline-src-block "lang" :value "value" :parameters '(:key val))
(org-ml-to-string))
=> "src_lang[:key val]{value}")
(defexamples org-ml-build-line-break
(->> (org-ml-build-line-break)
(org-ml-to-string))
=> "\\\\\n")
(defexamples org-ml-build-latex-fragment
(->> (org-ml-build-latex-fragment "$2+2=5$")
(org-ml-to-string))
=> "$2+2=5$")
(defexamples org-ml-build-macro
(->> (org-ml-build-macro "economics")
(org-ml-to-string))
=> "{{{economics}}}"
(->> (org-ml-build-macro "economics" :args '("s=d"))
(org-ml-to-string))
=> "{{{economics(s=d)}}}")
(defexamples org-ml-build-statistics-cookie
(->> (org-ml-build-statistics-cookie '(nil))
(org-ml-to-string))
=> "[%]"
(->> (org-ml-build-statistics-cookie '(nil nil))
(org-ml-to-string))
=> "[/]"
(->> (org-ml-build-statistics-cookie '(50))
(org-ml-to-string))
=> "[50%]"
(->> (org-ml-build-statistics-cookie '(1 3))
(org-ml-to-string))
=> "[1/3]")
(defexamples org-ml-build-target
(->> (org-ml-build-target "text")
(org-ml-to-string))
=> "<<text>>")
(defexamples org-ml-build-timestamp
(->> (org-ml-build-timestamp 'inactive 2019 1 15 2019 1 15)
(org-ml-to-string))
=> "[2019-01-15 Tue]"
(->> (org-ml-build-timestamp 'active-range 2019 1 15 2019 1 16)
(org-ml-to-string))
=> "<2019-01-15 Tue>--<2019-01-16 Wed>"
(->> (org-ml-build-timestamp
'inactive 2019 1 15 2019 1 15 :warning-type 'all
:warning-unit 'day :warning-value 1)
(org-ml-to-string))
=> "[2019-01-15 Tue -1d]")
(defexamples org-ml-build-verbatim
(->> (org-ml-build-verbatim "text")
(org-ml-to-string))
=> "=text="))
(def-example-subgroup "Branch Object Nodes"
nil
(defexamples org-ml-build-bold
(->> (org-ml-build-bold "text")
(org-ml-to-string))
=> "*text*")
(defexamples org-ml-build-footnote-reference
(->> (org-ml-build-footnote-reference)
(org-ml-to-string))
=> "[fn:]"
(->> (org-ml-build-footnote-reference :label "label")
(org-ml-to-string))
=> "[fn:label]"
(->> (org-ml-build-footnote-reference :label "label" "content")
(org-ml-to-string))
=> "[fn:label:content]")
(defexamples org-ml-build-italic
(->> (org-ml-build-italic "text")
(org-ml-to-string))
=> "/text/")
(defexamples org-ml-build-link
(->> (org-ml-build-link "target")
(org-ml-to-string))
=> "[[target]]"
(->> (org-ml-build-link "target" :type "file")
(org-ml-to-string))
=> "[[file:target]]"
(->> (org-ml-build-link "target" "desc")
(org-ml-to-string))
=> "[[target][desc]]")
(defexamples org-ml-build-radio-target
(->> (org-ml-build-radio-target "text")
(org-ml-to-string))
=> "<<<text>>>")
(defexamples org-ml-build-strike-through
(->> (org-ml-build-strike-through "text")
(org-ml-to-string))
=> "+text+")
(defexamples org-ml-build-superscript
(->> (org-ml-build-superscript "text")
(org-ml-to-string))
=> "^text")
(defexamples org-ml-build-subscript
(->> (org-ml-build-subscript "text")
(org-ml-to-string))
=> "_text")
(defexamples org-ml-build-table-cell
(->> (org-ml-build-table-cell "text")
(org-ml-to-string))
=> " text |")
(defexamples org-ml-build-underline
(->> (org-ml-build-underline "text")
(org-ml-to-string))
=> "_text_"))
(def-example-subgroup "Leaf Element Nodes"
nil
(defexamples org-ml-build-babel-call
(->> (org-ml-build-babel-call "name")
(org-ml-to-trimmed-string))
=> "#+call: name()"
(->> (org-ml-build-babel-call "name" :arguments '("arg=x"))
(org-ml-to-trimmed-string))
=> "#+call: name(arg=x)"
(->> (org-ml-build-babel-call "name" :inside-header '(:key val))
(org-ml-to-trimmed-string))
=> "#+call: name[:key val]()"
(->> (org-ml-build-babel-call "name" :end-header '(:key val))
(org-ml-to-trimmed-string))
=> "#+call: name() :key val")
(defexamples org-ml-build-clock
(->> (org-ml-build-clock (org-ml-build-timestamp! '(2019 1 1 0 0)))
(org-ml-to-trimmed-string))
=> "CLOCK: [2019-01-01 Tue 00:00]"
(->> (org-ml-build-timestamp! '(2019 1 1 0 0) :end '(2019 1 1 1 0))
;; TODO this is sloppy but also kinda a bad example anyways since
;; the shortcut function exists
(org-ml-set-property :type 'inactive-range)
(org-ml-build-clock)
(org-ml-to-trimmed-string))
=> "CLOCK: [2019-01-01 Tue 00:00]--[2019-01-01 Tue 01:00] => 1:00")
(defexamples org-ml-build-comment
;; TODO there is a bug that makes a blank string return a
;; blank string (it should return a "# ")
(->> (org-ml-build-comment "text")
(org-ml-to-trimmed-string))
=> "# text"
(->> (org-ml-build-comment "text\nless")
(org-ml-to-trimmed-string))
=> "# text\n# less")
(defexamples org-ml-build-comment-block
(->> (org-ml-build-comment-block)
(org-ml-to-trimmed-string))
=> (:result "#+begin_comment"
"#+end_comment")
(->> (org-ml-build-comment-block :value "text")
(org-ml-to-trimmed-string))
=> (:result "#+begin_comment"
"text"
"#+end_comment"))
(defexamples org-ml-build-diary-sexp
(->> (org-ml-build-diary-sexp)
(org-ml-to-trimmed-string))
=> "%%()"
(->> (org-ml-build-diary-sexp :value '(text))
(org-ml-to-trimmed-string))
=> "%%(text)")
(defexamples org-ml-build-example-block
(->> (org-ml-build-example-block)
(org-ml-to-trimmed-string))
=> (:result "#+begin_example"
"#+end_example")
(->> (org-ml-build-example-block :value "text")
(org-ml-to-trimmed-string))
=> (:result "#+begin_example"
" text"
"#+end_example")
(->> (org-ml-build-example-block :value "text" :switches '("switches"))
(org-ml-to-trimmed-string))
=> (:result "#+begin_example switches"
" text"
"#+end_example"))
(defexamples org-ml-build-export-block
(->> (org-ml-build-export-block "type" "value\n")
(org-ml-to-trimmed-string))
=> (:result "#+begin_export type"
"value"
"#+end_export"))
(defexamples org-ml-build-fixed-width
(->> (org-ml-build-fixed-width "text")
(org-ml-to-trimmed-string))
=> ": text")
(defexamples org-ml-build-horizontal-rule
(->> (org-ml-build-horizontal-rule)
(org-ml-to-trimmed-string))
=> "-----")
(defexamples org-ml-build-keyword
(->> (org-ml-build-keyword "FILETAGS" "tmsu")
(org-ml-to-trimmed-string))
=> "#+filetags: tmsu")
(defexamples org-ml-build-latex-environment
(->> (org-ml-build-latex-environment '("env" "text"))
(org-ml-to-trimmed-string))
=> (:result "\\begin{env}"
"text"
"\\end{env}"))
(defexamples org-ml-build-node-property
(->> (org-ml-build-node-property "key" "val")
(org-ml-to-trimmed-string))
=> ":key: val")
(defexamples org-ml-build-planning
(->> (org-ml-build-planning :closed (org-ml-build-timestamp! '(2019 1 1) :active nil))
(org-ml-to-trimmed-string))
=> "CLOSED: [2019-01-01 Tue]"
(->> (org-ml-build-planning :scheduled (org-ml-build-timestamp! '(2019 1 1) :active t))
(org-ml-to-trimmed-string))
=> "SCHEDULED: <2019-01-01 Tue>"
(->> (org-ml-build-planning :deadline (org-ml-build-timestamp! '(2019 1 1) :active t))
(org-ml-to-trimmed-string))
=> "DEADLINE: <2019-01-01 Tue>")
(defexamples org-ml-build-src-block
(->> (org-ml-build-src-block)
(org-ml-to-trimmed-string))
=> (:result "#+begin_src"
"#+end_src")
(->> (org-ml-build-src-block :value "body")
(org-ml-to-trimmed-string))
=> (:result "#+begin_src"
" body"
"#+end_src")
(->> (org-ml-build-src-block :value "body" :language "emacs-lisp")
(org-ml-to-trimmed-string))
=> (:result "#+begin_src emacs-lisp"
" body"
"#+end_src")
;; TODO pretty sure this makes no sense...
(->> (org-ml-build-src-block :value "body" :switches '("-n 20" "-r"))
(org-ml-to-trimmed-string))
=> (:result "#+begin_src -n 20 -r"
" body"
"#+end_src")
;; TODO and this...
(->> (org-ml-build-src-block :value "body" :parameters '(:key val))
(org-ml-to-trimmed-string))
=> (:result "#+begin_src :key val"
" body"
"#+end_src")))
(def-example-subgroup "Branch Element Nodes with Child Object Nodes"
nil
(defexamples org-ml-build-paragraph
(->> (org-ml-build-paragraph "text")
(org-ml-to-trimmed-string))
=> "text")
(defexamples org-ml-build-table-row
(->> (org-ml-build-table-cell "a")
(org-ml-build-table-row)
(org-ml-to-trimmed-string))
=> "| a |")
;; TODO should add a comment here to explain that newlines are necessary
(defexamples org-ml-build-verse-block
(->> (org-ml-build-verse-block "text\n")
(org-ml-to-trimmed-string))
=> (:result "#+begin_verse"
"text"
"#+end_verse")))
(def-example-subgroup "Branch Element Nodes with Child Element Nodes"
nil
(defexamples org-ml-build-org-data
(->> (org-ml-build-headline :title '("dummy"))
(org-ml-build-org-data)
(org-ml-to-trimmed-string))
=> "* dummy")
(defexamples org-ml-build-center-block
(->> (org-ml-build-center-block)
(org-ml-to-trimmed-string))
=> (:result "#+begin_center"
"#+end_center")
(->> (org-ml-build-paragraph "text")
(org-ml-build-center-block)
(org-ml-to-trimmed-string))
=> (:result "#+begin_center"
"text"
"#+end_center"))
(defexamples org-ml-build-drawer
(->> (org-ml-build-drawer "NAME")
(org-ml-to-trimmed-string))
=> (:result ":NAME:"
":END:")
(->> (org-ml-build-paragraph "text")
(org-ml-build-drawer "NAME")
(org-ml-to-trimmed-string))
=> (:result ":NAME:"
"text"
":END:"))
(defexamples org-ml-build-dynamic-block
(->> (org-ml-build-dynamic-block "empty")
(org-ml-to-trimmed-string))
=> (:result "#+begin: empty"
"#+end:")
(->> (org-ml-build-comment "I'm in here")
(org-ml-build-dynamic-block "notempty")
(org-ml-to-trimmed-string))
=> (:result "#+begin: notempty"
"# I'm in here"
"#+end:"))
(defexamples org-ml-build-footnote-definition
(->> (org-ml-build-paragraph "footnote contents")
(org-ml-build-footnote-definition "label")
(org-ml-to-trimmed-string))
=> "[fn:label] footnote contents")
(defexamples org-ml-build-headline
(->> (org-ml-build-headline)
(org-ml-to-trimmed-string))
=> "*"
(->> (org-ml-build-headline :level 2 :title '("dummy") :tags '("tmsu"))
(org-ml-to-trimmed-string))
=> "** dummy :tmsu:"
(->> (org-ml-build-headline :todo-keyword "TODO" :archivedp t
:commentedp t :priority ?A)
(org-ml-to-trimmed-string))
=> "* TODO COMMENT [#A] :ARCHIVE:"
:begin-hidden
(->> (org-ml-build-headline :level 2)
(org-ml-to-trimmed-string))
=> "**"
(->> (org-ml-build-headline :title '("dummy"))
(org-ml-to-trimmed-string))
=> "* dummy"
(->> (org-ml-build-headline :tags '("tmsu"))
(org-ml-to-trimmed-string))
=> "* :tmsu:"
(->> (org-ml-build-headline :todo-keyword "DONE")
(org-ml-to-trimmed-string))
=> "* DONE"
(->> (org-ml-build-headline :priority ?A)
(org-ml-to-trimmed-string))
=> "* [#A]"
(->> (org-ml-build-headline :footnote-section-p t)
(org-ml-to-trimmed-string))
=> "* Footnotes"
(->> (org-ml-build-headline :commentedp t)
(org-ml-to-trimmed-string))
=> "* COMMENT"
(->> (org-ml-build-headline :archivedp t)
(org-ml-to-trimmed-string))
=> "* :ARCHIVE:"
:end-hidden)
(defexamples org-ml-build-item
(->> (org-ml-build-paragraph "item contents")
(org-ml-build-item)
(org-ml-to-trimmed-string))
=> "- item contents"
(->> (org-ml-build-paragraph "item contents")
(org-ml-build-item :bullet 1)
(org-ml-to-trimmed-string))
=> "1. item contents"
(->> (org-ml-build-paragraph "item contents")
(org-ml-build-item :checkbox 'on)
(org-ml-to-trimmed-string))
=> "- [X] item contents"
(->> (org-ml-build-paragraph "item contents")
(org-ml-build-item :tag '("tmsu"))
(org-ml-to-trimmed-string))
=> "- tmsu :: item contents"
(->> (org-ml-build-paragraph "item contents")
(org-ml-build-item :counter 10)
(org-ml-to-trimmed-string))
=> "- [@10] item contents")
(defexamples org-ml-build-plain-list
(->> (org-ml-build-paragraph "item contents")
(org-ml-build-item)
(org-ml-build-plain-list)
(org-ml-to-trimmed-string))
=> "- item contents")
(defexamples org-ml-build-property-drawer
(->> (org-ml-build-property-drawer)
(org-ml-to-trimmed-string))
=> (:result ":PROPERTIES:"
":END:")
(->> (org-ml-build-node-property "key" "val")
(org-ml-build-property-drawer)
(org-ml-to-trimmed-string))
=> (:result ":PROPERTIES:"
":key: val"
":END:"))
(defexamples org-ml-build-quote-block
(->> (org-ml-build-quote-block)
(org-ml-to-trimmed-string))
=> (:result "#+begin_quote"
"#+end_quote")
(->> (org-ml-build-paragraph "quoted stuff")
(org-ml-build-quote-block)
(org-ml-to-trimmed-string))
=> (:result "#+begin_quote"
"quoted stuff"
"#+end_quote"))
(defexamples org-ml-build-section
(->> (org-ml-build-paragraph "text")
(org-ml-build-section)
(org-ml-to-trimmed-string))
=> "text")
;; TODO add :parameters to test
(defexamples org-ml-build-special-block
(->> (org-ml-build-special-block "monad")
(org-ml-to-trimmed-string))
=> (:result "#+begin_monad"
"#+end_monad")
(->> (org-ml-build-comment "Launch missiles")
(org-ml-build-special-block "monad")
(org-ml-to-trimmed-string))
=> (:result "#+begin_monad"
"# Launch missiles"
"#+end_monad"))
(defexamples org-ml-build-table
(->> (org-ml-build-table-cell "cell")
(org-ml-build-table-row)
(org-ml-build-table)
(org-ml-to-trimmed-string))
=> "| cell |"))
(def-example-subgroup "Miscellaneous Builders"
nil
;; (defexamples-content org-ml-clone-node
;; nil
;; (:buffer "dolly")
;; (let* ((node1 (org-ml-parse-this-element))
;; (node2 (org-ml-clone-node node1)))
;; (equal node1 node2))
;; => t
;; (let* ((node1 (org-ml-parse-this-element))
;; (node2 (org-ml-clone-node node1)))
;; (eq node1 node2))
;; => nil)
;; (defexamples-content org-ml-clone-node-n
;; nil
;; (:buffer "dolly")
;; (-let* ((node1 (org-ml-parse-this-element))
;; ((node2 node3) (org-ml-clone-node-n 2 node1)))
;; (or (equal node1 node2)
;; (equal node1 node3)
;; (equal node2 node3)))
;; => t
;; (-let* ((node1 (org-ml-parse-this-element))
;; ((node2 node3) (org-ml-clone-node-n 2 node1)))
;; (or (eq node1 node2)
;; (eq node1 node3)
;; (eq node2 node3)))
;; => nil)
(defexamples org-ml-build-secondary-string!
(->> (org-ml-build-secondary-string! "I'm plain")
(-map #'org-ml-get-type))
=> '(plain-text)
(->> (org-ml-build-secondary-string! "I'm *not* plain")
(-map #'org-ml-get-type))
=> '(plain-text bold plain-text)
(->> (org-ml-build-secondary-string! "1. I'm *not* a plain list")
(-map #'org-ml-get-type))
=> '(plain-text bold plain-text)
(->> (org-ml-build-secondary-string! "* I'm not an object")
(-map #'org-ml-get-type))
=> '(plain-text))
(defexamples org-ml-build-table-row-hline
(->> (org-ml-build-table
(org-ml-build-table-row
(org-ml-build-table-cell "text"))
(org-ml-build-table-row-hline))
(org-ml-to-trimmed-string))
=> (:result "| text |"
"|------|"))
(defexamples org-ml-build-timestamp-diary
(->> (org-ml-build-timestamp-diary '(diary-float t 4 2))
(org-ml-to-string))
=> "<%%(diary-float t 4 2)>"
(->> (org-ml-build-timestamp-diary '(diary-float t 4 2) :start '(0 0))
(org-ml-to-string))
=> "<%%(diary-float t 4 2) 00:00>"
(->> (org-ml-build-timestamp-diary '(diary-float t 4 2) :start '(0 0) :end '(1 0))
(org-ml-to-string))
=> "<%%(diary-float t 4 2) 00:00-01:00>"
:begin-hidden
(->> (org-ml-build-timestamp-diary '(diary-float t 4 2) :end '(1 0))
(org-ml-to-string))
!!> arg-type-error
:end-hidden))
(def-example-subgroup "Shorthand Builders"
"Build nodes with more convenient/shorter syntax."
(defexamples org-ml-build-timestamp!
(->> (org-ml-build-timestamp! '(2019 1 1))
(org-ml-to-string))
=> "[2019-01-01 Tue]"
(->> (org-ml-build-timestamp! '(2019 1 1 12 0)
:active t
:warning '(all 1 day)
:repeater '(cumulate 1 month))
(org-ml-to-string))
=> "<2019-01-01 Tue 12:00 +1m -1d>"
(->> (org-ml-build-timestamp! '(2019 1 1) :end '(2019 1 2))
(org-ml-to-string))
=> "[2019-01-01 Tue]--[2019-01-02 Wed]")
(defexamples org-ml-build-clock!
(->> (org-ml-build-clock! '(2019 1 1))
(org-ml-to-trimmed-string))
=> "CLOCK: [2019-01-01 Tue]"
(->> (org-ml-build-clock! '(2019 1 1 12 0))
(org-ml-to-trimmed-string))
=> "CLOCK: [2019-01-01 Tue 12:00]"
(->> (org-ml-build-clock! '(2019 1 1 12 0) :end '(2019 1 1 13 0))
(org-ml-to-trimmed-string))
=> "CLOCK: [2019-01-01 Tue 12:00]--[2019-01-01 Tue 13:00] => 1:00")
(defexamples org-ml-build-planning!
(->> (org-ml-build-planning! :closed '(2019 1 1))
(org-ml-to-trimmed-string))
=> "CLOSED: [2019-01-01 Tue]"
(->> (org-ml-build-planning! :closed '(2019 1 1)
:scheduled '(2018 1 1))
(org-ml-to-trimmed-string))
=> "SCHEDULED: <2018-01-01 Mon> CLOSED: [2019-01-01 Tue]"
(->> (org-ml-build-planning! :scheduled '(2019 1 1 &warning all 1 day &repeater cumulate 1 month))
(org-ml-to-trimmed-string))
=> "SCHEDULED: <2019-01-01 Tue +1m -1d>")
(defexamples org-ml-build-property-drawer!
(->> (org-ml-build-property-drawer! '("key" "val"))
(org-ml-to-trimmed-string))
=> (:result ":PROPERTIES:"
":key: val"
":END:"))
(defexamples org-ml-build-headline!
(->> (org-ml-build-headline! :title-text "really impressive title")
(org-ml-to-trimmed-string))
=> "* really impressive title"
(->> (org-ml-build-headline! :title-text "really impressive title"
:statistics-cookie '(0 9000))
(org-ml-to-trimmed-string))
=> "* really impressive title [0/9000]"
(->> (org-ml-build-headline!
:title-text "really impressive title"
:section-children
(list (org-ml-build-property-drawer! '("key" "val"))
(org-ml-build-paragraph! "section text"))
(org-ml-build-headline! :title-text "subhead"))
(org-ml-to-trimmed-string))
=> (:result "* really impressive title"
":PROPERTIES:"
":key: val"
":END:"
"section text"
"** subhead"))
(defexamples org-ml-build-item!
(->> (org-ml-build-item!
:bullet 1
:tag "complicated *tag*"
:paragraph "petulant /frenzy/"
(org-ml-build-plain-list
(org-ml-build-item! :bullet '- :paragraph "below")))
(org-ml-to-trimmed-string))
=> (:result "1. complicated *tag* :: petulant /frenzy/"
" - below"))
(defexamples org-ml-build-paragraph!
(->> (org-ml-build-paragraph! "stuff /with/ *formatting*" :post-blank 2)
(org-ml-to-string))
=> (:result "stuff /with/ *formatting*"
""
""
"")
(->> (org-ml-build-paragraph! "* stuff /with/ *formatting*")
(org-ml-to-string))
=> (:result "* stuff /with/ *formatting*"
""))
(defexamples org-ml-build-table-cell!
(->> (org-ml-build-table-cell! "rage")
(org-ml-to-trimmed-string))
=> "rage |"
(->> (org-ml-build-table-cell! "*rage*")
(org-ml-to-trimmed-string))
=> "*rage* |")
(defexamples org-ml-build-table-row!
(->> (org-ml-build-table-row! '("R" "A" "G" "E"))
(org-ml-to-trimmed-string))
=> "| R | A | G | E |"
(->> (org-ml-build-table-row! '("S" "" "X"))
(org-ml-to-trimmed-string))
=> "| S | | X |"
(->> (org-ml-build-table-row! 'hline)
(org-ml-to-trimmed-string))
=> "|-")
(defexamples org-ml-build-table!
(->> (org-ml-build-table! '("R" "A") '("G" "E"))
(org-ml-to-trimmed-string))
=> (:result "| R | A |"
"| G | E |")
(->> (org-ml-build-table! '("S" "") '("" "X"))
(org-ml-to-trimmed-string))
=> (:result "| S | |"
"| | X |")
(->> (org-ml-build-table! '("L" "O") 'hline '("V" "E"))
(org-ml-to-trimmed-string))
=> (:result "| L | O |"
"|---+---|"
"| V | E |")))
(def-example-subgroup "Logbook Item Builders"
"Build item nodes for inclusion in headline logbooks"
(defexamples org-ml-build-log-note
(-> (- 1546300800 (car (current-time-zone)))
(org-ml-build-log-note "noteworthy")
(org-ml-to-trimmed-string))
=> (:result "- Note taken on [2019-01-01 Tue 00:00] \\\\"
" noteworthy"))
(defexamples org-ml-build-log-done
(-> (- 1546300800 (car (current-time-zone)))
(org-ml-build-log-done)
(org-ml-to-trimmed-string))
=> (:result "- CLOSING NOTE [2019-01-01 Tue 00:00]")
(-> (- 1546300800 (car (current-time-zone)))
(org-ml-build-log-done "noteworthy")
(org-ml-to-trimmed-string))
=> (:result "- CLOSING NOTE [2019-01-01 Tue 00:00] \\\\"
" noteworthy"))
(defexamples org-ml-build-log-refile
(-> (- 1546300800 (car (current-time-zone)))
(org-ml-build-log-refile)
(org-ml-to-trimmed-string))
=> (:result "- Refiled on [2019-01-01 Tue 00:00]")
(-> (- 1546300800 (car (current-time-zone)))
(org-ml-build-log-refile "noteworthy")
(org-ml-to-trimmed-string))
=> (:result "- Refiled on [2019-01-01 Tue 00:00] \\\\"
" noteworthy"))
(defexamples org-ml-build-log-state
(-> (- 1546300800 (car (current-time-zone)))
(org-ml-build-log-state "HOLD" "TODO")
(org-ml-to-trimmed-string))
=> (:result "- State \"HOLD\" from \"TODO\" [2019-01-01 Tue 00:00]")
(-> (- 1546300800 (car (current-time-zone)))
(org-ml-build-log-state "HOLD" "TODO" "noteworthy")
(org-ml-to-trimmed-string))
=> (:result "- State \"HOLD\" from \"TODO\" [2019-01-01 Tue 00:00] \\\\"
" noteworthy"))
(defexamples org-ml-build-log-deldeadline
(-> (- 1546300800 (car (current-time-zone)))
(org-ml-build-log-deldeadline (org-ml-build-timestamp! '(2019 1 2)))
(org-ml-to-trimmed-string))
=> (:result "- Removed deadline, was \"[2019-01-02 Wed]\" on [2019-01-01 Tue 00:00]")
(-> (- 1546300800 (car (current-time-zone)))
(org-ml-build-log-deldeadline (org-ml-build-timestamp! '(2019 1 2)) "noteworthy")
(org-ml-to-trimmed-string))
=> (:result "- Removed deadline, was \"[2019-01-02 Wed]\" on [2019-01-01 Tue 00:00] \\\\"
" noteworthy"))
(defexamples org-ml-build-log-delschedule
(-> (- 1546300800 (car (current-time-zone)))
(org-ml-build-log-delschedule (org-ml-build-timestamp! '(2019 1 2)))
(org-ml-to-trimmed-string))
=> (:result "- Not scheduled, was \"[2019-01-02 Wed]\" on [2019-01-01 Tue 00:00]")
(-> (- 1546300800 (car (current-time-zone)))
(org-ml-build-log-delschedule (org-ml-build-timestamp! '(2019 1 2)) "noteworthy")
(org-ml-to-trimmed-string))
=> (:result "- Not scheduled, was \"[2019-01-02 Wed]\" on [2019-01-01 Tue 00:00] \\\\"
" noteworthy"))
(defexamples org-ml-build-log-redeadline
(-> (- 1546300800 (car (current-time-zone)))
(org-ml-build-log-redeadline (org-ml-build-timestamp! '(2019 1 2)))
(org-ml-to-trimmed-string))
=> (:result "- New deadline from \"[2019-01-02 Wed]\" on [2019-01-01 Tue 00:00]")
(-> (- 1546300800 (car (current-time-zone)))
(org-ml-build-log-redeadline (org-ml-build-timestamp! '(2019 1 2)) "noteworthy")
(org-ml-to-trimmed-string))
=> (:result "- New deadline from \"[2019-01-02 Wed]\" on [2019-01-01 Tue 00:00] \\\\"
" noteworthy"))
(defexamples org-ml-build-log-reschedule
(-> (- 1546300800 (car (current-time-zone)))
(org-ml-build-log-reschedule (org-ml-build-timestamp! '(2019 1 2)))
(org-ml-to-trimmed-string))
=> (:result "- Rescheduled from \"[2019-01-02 Wed]\" on [2019-01-01 Tue 00:00]")
(-> (- 1546300800 (car (current-time-zone)))
(org-ml-build-log-reschedule (org-ml-build-timestamp! '(2019 1 2)) "noteworthy")
(org-ml-to-trimmed-string))
=> (:result "- Rescheduled from \"[2019-01-02 Wed]\" on [2019-01-01 Tue 00:00] \\\\"
" noteworthy"))
(defexamples org-ml-build-log-type
(let ((org-log-note-headings '((test . "Changed %s from %S on %t by %u")))
(ut (- 1546300800 (car (current-time-zone)))))
(->> (org-ml-build-log-type 'test :unixtime ut :old "TODO" :new
"DONE" :username "shadowbrokers"
:note "We're coming for you")
(org-ml-to-trimmed-string)))
=> (:result
"- Changed \"DONE\" from \"TODO\" on [2019-01-01 Tue 00:00] by shadowbrokers \\\\"
" We're coming for you")
:begin-hidden
(let ((org-log-note-headings '((test . "My note is %t"))))
(->> (- 1546300800 (car (current-time-zone)))
(org-ml-build-log-type 'test :unixtime)
(org-ml-to-trimmed-string)))
=> "- My note is [2019-01-01 Tue 00:00]"
(let ((org-log-note-headings '((test . "My note is %T"))))
(->> (- 1546300800 (car (current-time-zone)))
(org-ml-build-log-type 'test :unixtime)
(org-ml-to-trimmed-string)))
=> "- My note is <2019-01-01 Tue 00:00>"
(let ((org-log-note-headings '((test . "My note is %d"))))
(->> (- 1546300800 (car (current-time-zone)))
(org-ml-build-log-type 'test :unixtime)
(org-ml-to-trimmed-string)))
=> "- My note is [2019-01-01 Tue]"
(let ((org-log-note-headings '((test . "My note is %D"))))
(->> (- 1546300800 (car (current-time-zone)))
(org-ml-build-log-type 'test :unixtime)
(org-ml-to-trimmed-string)))
=> "- My note is <2019-01-01 Tue>"
(let ((org-log-note-headings '((test . "My name is %u"))))
(->> (org-ml-build-log-type 'test :username "slim")
(org-ml-to-trimmed-string)))
=> "- My name is slim"
(let ((org-log-note-headings '((test . "My name is %U"))))
(->> (org-ml-build-log-type 'test :full-username "slimshady")
(org-ml-to-trimmed-string)))
=> "- My name is slimshady"
(let ((org-log-note-headings '((test . "My note is %S"))))
(->> (org-ml-build-log-type 'test :old "DONE")
(org-ml-to-trimmed-string)))
=> "- My note is \"DONE\""
(let ((org-log-note-headings '((test . "My note is %S"))))
(->> (org-ml-build-timestamp! '(2019 1 1 0 0))
(org-ml-build-log-type 'test :old)
(org-ml-to-trimmed-string)))
=> "- My note is \"[2019-01-01 Tue 00:00]\""
(let ((org-log-note-headings '((test . "My note is %s"))))
(->> (org-ml-build-log-type 'test :new "DONE")
(org-ml-to-trimmed-string)))
=> "- My note is \"DONE\""
(let ((org-log-note-headings '((test . "My note is %s"))))
(->> (org-ml-build-timestamp! '(2019 1 1 0 0))
(org-ml-build-log-type 'test :new)
(org-ml-to-trimmed-string)))
=> "- My note is \"[2019-01-01 Tue 00:00]\""
:end-hidden
)
))
(def-example-group "Type Predicates"
"Test node types."
(defexamples-content org-ml-get-type
nil
(:buffer "*I'm emboldened*")
(->> (org-ml-parse-this-object)
(org-ml-get-type))
=> 'bold
(:buffer "* I'm the headliner")
(->> (org-ml-parse-this-element)
(org-ml-get-type))
=> 'headline
(:buffer "[2112-12-21 Wed]")
(->> (org-ml-parse-this-object)
(org-ml-get-type))
=> 'timestamp)
(defexamples-content org-ml-is-type
nil
(:buffer "*ziltoid*")
(->> (org-ml-parse-this-object)
(org-ml-is-type 'bold))
=> t
(->> (org-ml-parse-this-object)
(org-ml-is-type 'italic))
=> nil)
(defexamples-content org-ml-is-any-type
nil
(:buffer "*ziltoid*")
(->> (org-ml-parse-this-object)
(org-ml-is-any-type '(bold)))
=> t
(->> (org-ml-parse-this-object)
(org-ml-is-any-type '(bold italic)))
=> t
(->> (org-ml-parse-this-object)
(org-ml-is-any-type '(italic)))
=> nil)
(defexamples-content org-ml-is-element
nil
(:buffer "*ziltoid*")
(:comment "Parsing this text as an element node gives a paragraph node")
(->> (org-ml-parse-this-element)
(org-ml-is-element))
=> t
(:comment "Parsing the same text as an object node gives a bold node")
(->> (org-ml-parse-this-object)
(org-ml-is-element))
=> nil)
(defexamples-content org-ml-is-branch-node
nil
(:buffer "*ziltoid*")
(:comment "Parsing this as an element node gives a paragraph node"
"(a branch node)")
(->> (org-ml-parse-this-element)
(org-ml-is-branch-node))
=> t
(:comment "Parsing this as an object node gives a bold node"
"(also a branch node)")
(->> (org-ml-parse-this-object)
(org-ml-is-branch-node))
=> t
(:buffer "~ziltoid~")
(:comment "Parsing this as an object node gives a code node"
"(not a branch node)")
(->> (org-ml-parse-this-object)
(org-ml-is-branch-node))
=> nil
(:buffer "# ziltoid")
(:comment "Parsing this as an element node gives a comment node"
"(also not a branch node)")
(->> (org-ml-parse-this-element)
(org-ml-is-branch-node))
=> nil
(:buffer "* I'm so great")
(:comment "Parsing this as an element node gives a headline node"
"(a branch node)")
(->> (org-ml-parse-this-element)
(org-ml-is-branch-node))
=> t)
(defexamples-content org-ml-node-may-have-child-objects
nil
(:buffer "*ziltoid*")
(:comment "Parsing this as an element node gives a paragraph node"
"(can have child object nodes)")
(->> (org-ml-parse-this-element)
(org-ml-node-may-have-child-objects))
=> t
(:comment "Parsing this as an object node gives a bold node"
"(also can have child object nodes)")
(->> (org-ml-parse-this-object)
(org-ml-node-may-have-child-objects))
=> t
(:buffer "~ziltoid~")
(:comment "Parsing this as an object node gives a code node"
"(not a branch node)")
(->> (org-ml-parse-this-object)
(org-ml-node-may-have-child-objects))
=> nil
(:buffer "# ziltoid")
(:comment "Parsing this as an element node gives a comment node"
"(not a branch node)")
(->> (org-ml-parse-this-element)
(org-ml-node-may-have-child-objects))
=> nil
(:buffer "* I'm so great")
(:comment "Parsing this as an element node gives a headline node"
"(can only have child element nodes)")
(->> (org-ml-parse-this-element)
(org-ml-node-may-have-child-objects))
=> nil)
(defexamples-content org-ml-node-may-have-child-elements
nil
(:buffer "* I'm so great")
(:comment "Parsing this as an element node gives a headline node"
"(can have child element nodes)")
(->> (org-ml-parse-this-element)
(org-ml-node-may-have-child-elements))
=> t
(:buffer "*ziltoid*")
(:comment "Parsing this as an element node gives a paragraph node"
"(can only have child object nodes)")
(->> (org-ml-parse-this-element)
(org-ml-node-may-have-child-elements))
=> nil
(:buffer "# ziltoid")
(:comment "Parsing this as an element node gives a comment node"
"(not a branch node)")
(->> (org-ml-parse-this-element)
(org-ml-node-may-have-child-elements))
=> nil))
(def-example-group "Property Manipulation"
"Set, get, and map properties of nodes."
(def-example-subgroup "Generic"
nil
(defexamples-content org-ml-contains-point-p
nil
(:buffer "*findme*")
(->> (org-ml-parse-this-object)
(org-ml-contains-point-p 2))
=> t
(->> (org-ml-parse-this-object)
(org-ml-contains-point-p 10))
=> nil)
(defexamples-content org-ml-set-property
nil
(:buffer "#+call: ktulu()")
(org-ml->> (org-ml-parse-this-element)
(org-ml-set-property :call "cthulhu")
(org-ml-set-property :inside-header '(:cache no))
(org-ml-set-property :arguments '("x=4"))
(org-ml-set-property :end-header '(:exports results))
(org-ml-to-trimmed-string))
=> "#+call: cthulhu[:cache no](x=4) :exports results"
:begin-hidden
(:buffer "CLOCK: [2019-01-01 Tue]")
(org-ml->> (org-ml-parse-this-element)
(org-ml-set-property
:value (org-ml-build-timestamp! '(2019 1 1) :end '(2019 1 2)))
(org-ml-to-trimmed-string))
=> "CLOCK: [2019-01-01 Tue]--[2019-01-02 Wed] => 24:00"
(:buffer "~learn to~")
(org-ml->> (org-ml-parse-this-object)
(org-ml-set-property :value "why?")
(org-ml-to-trimmed-string))
=> "~why?~"
(:buffer "# not here")
(org-ml->> (org-ml-parse-this-element)
(org-ml-set-property :value "still not here")
(org-ml-to-trimmed-string))
=> "# still not here"
(:buffer "#+begin_comment"
"not here"
"#+end_comment")
(org-ml->> (org-ml-parse-this-element)
(org-ml-set-property :value "still not here")
(org-ml-to-trimmed-string))
=> (:result "#+begin_comment"
"still not here"
"#+end_comment")
(:buffer "%%(print :valueble)")
(org-ml->> (org-ml-parse-this-element)
(org-ml-set-property :value '(print :invaluble))
(org-ml-to-trimmed-string))
=> "%%(print :invaluble)"
(:buffer ":LOGBOOK:"
":END:")
(org-ml->> (org-ml-parse-this-element)
(org-ml-set-property :drawer-name "BOOKOFSOULS")
(org-ml-to-trimmed-string))
=> (:result ":BOOKOFSOULS:"
":END:")
(:buffer "#+begin: blockhead"
"#+end:")
(org-ml->> (org-ml-parse-this-element)
(org-ml-set-property :block-name "blockfoot")
(org-ml-set-property :arguments '(:cache no))
(org-ml-to-trimmed-string))
=> (:result "#+begin: blockfoot :cache no"
"#+end:")
(:buffer "\\pi")
(org-ml->> (org-ml-parse-this-object)
(org-ml-set-property :name "gamma")
(org-ml-set-property :use-brackets-p t)
(org-ml-to-trimmed-string))
=> "\\gamma{}"
;; TODO test org-src-preserve-indentation
(:buffer "#+begin_example"
"#+end_example")
(org-ml->> (org-ml-parse-this-element)
(org-ml-set-property :switches '("-n"))
(org-ml-set-property :value "example.com")
(org-ml-to-trimmed-string))
=> (:buffer "#+begin_example -n"
" example.com"
"#+end_example")
(:buffer "#+begin_export latex"
"#+end_export")
(org-ml->> (org-ml-parse-this-element)
(org-ml-set-property :type "domestic")
(org-ml-set-property :value "bullets, bombs, and bigotry")
(org-ml-to-trimmed-string))
=> (:buffer "#+begin_export domestic"
"bullets, bombs, and bigotry"
"#+end_export")
(:buffer "@@back-end:value@@")
(org-ml->> (org-ml-parse-this-object)
(org-ml-set-property :back-end "latex")
(org-ml-set-property :value "new-value")
(org-ml-to-trimmed-string))
=> "@@latex:new-value@@"
(:buffer ": fixed")
(org-ml->> (org-ml-parse-this-element)
(org-ml-set-property :value "unfixed")
(org-ml-to-trimmed-string))
=> ": unfixed"
(:buffer "[fn:whitelabel] society")
(org-ml->> (org-ml-parse-this-element)
(org-ml-set-property :label "blacklabel")
(org-ml-to-trimmed-string))
=> "[fn:blacklabel] society"
(:buffer "* dummy"
"stuff")
(org-ml->> (org-ml-parse-this-element)
(org-ml-set-property :archivedp t)
(org-ml-set-property :commentedp t)
(org-ml-set-property :level 2)
(org-ml-set-property :pre-blank 1)
(org-ml-set-property :priority ?A)
(org-ml-set-property :tags '("tmsu"))
(org-ml-set-property :title '("smartie"))
(org-ml-set-property :todo-keyword "TODO")
(org-ml-to-trimmed-string))
=> (:result "** TODO COMMENT [#A] smartie :tmsu:ARCHIVE:"
""
"stuff")
:begin-hidden
(org-ml->> (org-ml-parse-this-element)
(org-ml-set-property :footnote-section-p t)
(org-ml-to-trimmed-string))
=> (:result "* Footnotes"
"stuff")
:end-hidden
(:buffer "call_kthulu()")
(org-ml->> (org-ml-parse-this-object)
(org-ml-set-property :call "cthulhu")
(org-ml-set-property :inside-header '(:cache no))
(org-ml-set-property :arguments '("x=4"))
(org-ml-set-property :end-header '(:exports results))
(org-ml-to-trimmed-string))
=> "call_cthulhu[:cache no](x=4)[:exports results]"
(:buffer "src_emacs{(print 'yeah-boi)}")
(org-ml->> (org-ml-parse-this-object)
(org-ml-set-property :language "python")
(org-ml-set-property :parameters '(:cache no))
(org-ml-set-property :value "print \"yeah boi\"")
(org-ml-to-trimmed-string))
=> "src_python[:cache no]{print \"yeah boi\"}"
:end-hidden
(:buffer "- thing")
(org-ml->> (org-ml-parse-this-item)
(org-ml-set-property :bullet 1)
(org-ml-set-property :checkbox 'on)
(org-ml-set-property :counter 2)
(org-ml-set-property :tag '("tmsu"))
(org-ml-to-trimmed-string))
=> "1. [@2] [X] tmsu :: thing"
:begin-hidden
(:buffer "#+KEY: VAL")
(org-ml->> (org-ml-parse-this-element)
(org-ml-set-property :key "kee")
(org-ml-set-property :value "vahl")
(org-ml-to-trimmed-string))
=> "#+kee: vahl"
(:buffer "\begin{env}"
"body"
"\end{env}")
(org-ml->> (org-ml-parse-this-element)
(org-ml-set-property :value "\begin{vne}\nbody\end{vne}")
(org-ml-to-trimmed-string))
=> (:buffer "\begin{vne}"
"body"
"\end{vne}")
(:buffer "$2+2=4$")
(org-ml->> (org-ml-parse-this-object)
(org-ml-set-property :value "$2+2=5$")
(org-ml-to-trimmed-string))
=> "$2+2=5$"
(:buffer "https://example.com")
(org-ml->> (org-ml-parse-this-object)
(org-ml-set-property :path "/dev/null")
(org-ml-set-property :type "file")
(org-ml-set-property :format 'bracket)
(org-ml-to-trimmed-string))
=> "[[file:/dev/null]]"
(:buffer "{{{economics}}}")
(org-ml->> (org-ml-parse-this-object)
(org-ml-set-property :key "freakonomics")
(org-ml-set-property :args '("x=4" "y=2"))
(org-ml-to-trimmed-string))
=> "{{{freakonomics(x=4,y=2)}}}"
(:buffer "* dummy"
":PROPERTIES:"
":KEY: VAL"
":END:")
(org-ml->> (org-ml-parse-this-headline)
(org-ml-headline-get-section)
(-first-item)
(org-ml-get-children)
(-first-item)
(org-ml-set-property :key "kee")
(org-ml-set-property :value "vahl")
(org-ml-to-trimmed-string))
=> ":kee: vahl"
(:buffer "* dummy"
"CLOSED: <2019-01-01 Tue>")
(org-ml->> (org-ml-parse-this-headline)
(org-ml-headline-get-section)
(-first-item)
(org-ml-set-property
:closed (org-ml-build-timestamp! '(2019 1 2) :active nil))
(org-ml-to-trimmed-string))
=> "CLOSED: [2019-01-02 Wed]"
(:buffer "#+begin_special"
"#+end_special")
(org-ml->> (org-ml-parse-this-element)
(org-ml-set-property :type "talent")
(org-ml-to-trimmed-string))
=> (:result "#+begin_talent"
"#+end_talent")
(:buffer "#+begin_src"
"something amorphous"
"#+end_src")
(org-ml->> (org-ml-parse-this-element)
(org-ml-set-property :language "emacs")
(org-ml-set-property :value "(print 'hi)")
(org-ml-set-property :parameters '(:cache no))
(org-ml-set-property :switches '("-n"))
;; TODO test org-src-preserve-indentation
(org-ml-to-trimmed-string))
=> (:result "#+begin_src emacs -n :cache no"
" (print 'hi)"
"#+end_src")
(:buffer "* dummy [50%]")
(org-ml->> (org-ml-parse-this-headline)
(org-ml-headline-get-statistics-cookie)
(org-ml-set-property :value '(0 5))
(org-ml-to-trimmed-string))
=> "[0/5]"
(:buffer "sub_woofer")
(org-ml->> (org-ml-parse-object-at 5)
(org-ml-set-property :use-brackets-p t)
(org-ml-to-trimmed-string))
=> "_{woofer}"
(:buffer "super^woofer")
(org-ml->> (org-ml-parse-object-at 7)
(org-ml-set-property :use-brackets-p t)
(org-ml-to-trimmed-string))
=> "^{woofer}"
(:buffer "| a |")
(org-ml->> (org-ml-parse-this-element)
(org-ml-set-property :tblfm '("x=$2"))
(org-ml-to-trimmed-string))
=> (:result "| a |"
"#+TBLFM: x=$2")
(:buffer "<<found>>")
(org-ml->> (org-ml-parse-this-object)
(org-ml-set-property :value "lost")
(org-ml-to-trimmed-string))
=> "<<lost>>"
(:buffer "[2019-01-01 Tue]")
(org-ml->> (org-ml-parse-this-object)
(org-ml-set-property :year-start 2020)
(org-ml-set-property :month-start 2)
(org-ml-set-property :day-start 2)
(org-ml-set-property :hour-start 12)
(org-ml-set-property :minute-start 0)
(org-ml-set-property :year-end 2020)
(org-ml-set-property :month-end 2)
(org-ml-set-property :day-end 3)
(org-ml-set-property :hour-end 12)
(org-ml-set-property :minute-end 0)
(org-ml-set-property :type 'active-range)
(org-ml-set-property :warning-type 'all)
(org-ml-set-property :warning-unit 'day)
(org-ml-set-property :warning-value 1)
(org-ml-set-property :repeater-type 'cumulate)
(org-ml-set-property :repeater-unit 'day)
(org-ml-set-property :repeater-value 1)
(org-ml-to-trimmed-string))
=> "<2020-02-02 Sun 12:00 +1d -1d>--<2020-02-03 Mon 12:00 +1d -1d>"
(:buffer "=I am not a crook=")
(org-ml->> (org-ml-parse-this-object)
(org-ml-set-property :value "You totally are")
(org-ml-to-trimmed-string))
=> "=You totally are="
(:buffer "plain")
(org-ml->> (org-ml-set-property :post-blank 1 "plain")
(org-ml-to-string))
=> "plain "
(:buffer "*not plain*")
(org-ml->> (org-ml-parse-this-object)
(org-ml-set-property :post-blank 1)
(org-ml-to-string))
=> "*not plain* "
;; affiliated keywords
(:buffer "short paragraph")
(org-ml->> (org-ml-parse-this-element)
(org-ml-set-property :name "foo")
(org-ml-to-trimmed-string))
=> (:result "#+name: foo"
"short paragraph")
(org-ml->> (org-ml-parse-this-element)
(org-ml-set-property :attr_bar '("foo"))
(org-ml-to-trimmed-string))
=> (:result "#+attr_bar: foo"
"short paragraph")
(org-ml->> (org-ml-parse-this-element)
(org-ml-set-property :header '((:k1 "h1") (:k2 "h2")))
(org-ml-to-trimmed-string))
=> (:result "#+header: :k1 h1"
"#+header: :k2 h2"
"short paragraph")
(org-ml->> (org-ml-parse-this-element)
(org-ml-set-property :results '("bar" "foo"))
(org-ml-to-trimmed-string))
=> (:result "#+results[bar]: foo"
"short paragraph")
(org-ml->> (org-ml-parse-this-element)
(org-ml-set-property :caption '("cap"))
(org-ml-to-trimmed-string))
=> (:result "#+caption: cap"
"short paragraph")
(org-ml->> (org-ml-parse-this-element)
(org-ml-set-property :caption '(("foo" "cap")))
(org-ml-to-trimmed-string))
=> (:result "#+caption[foo]: cap"
"short paragraph")
(org-ml->> (org-ml-parse-this-element)
(org-ml-set-property :caption '(("FOO" "CAP") ("foo" "cap")))
(org-ml-to-trimmed-string))
=> (:result "#+caption[FOO]: CAP"
"#+caption[foo]: cap"
"short paragraph")
(:buffer "#+caption: cap"
"short paragraph")
(org-ml->> (org-ml-parse-this-element)
(org-ml-set-property :caption nil)
(org-ml-to-trimmed-string))
=> "short paragraph"
(:buffer "#+name: deleteme"
"short paragraph")
(org-ml->> (org-ml-parse-this-element)
(org-ml-set-property :name nil)
(org-ml-to-trimmed-string))
=> "short paragraph"
:end-hidden
(:buffer "* not valuable")
(:comment "Throw error when setting a property that doesn't exist")
(org-ml->> (org-ml-parse-this-headline)
(org-ml-set-property :value "wtf")
(org-ml-to-trimmed-string))
!!> arg-type-error
(:comment "Throw error when setting to an improper type")
(org-ml->> (org-ml-parse-this-headline)
(org-ml-set-property :title 666)
(org-ml-to-trimmed-string))
!!> arg-type-error)
(defexamples-content org-ml-get-property
nil
(:buffer "#+call: ktulu(x=4) :exports results")
(->> (org-ml-parse-this-element)
(org-ml-get-property :call))
=> "ktulu"
(->> (org-ml-parse-this-element)
(org-ml-get-property :inside-header))
=> nil
:begin-hidden
(->> (org-ml-parse-this-element)
(org-ml-get-property :arguments))
=> '("x=4")
(->> (org-ml-parse-this-element)
(org-ml-get-property :end-header))
=> '(:exports results)
(:buffer "CLOCK: [2019-01-01 Tue]")
(->> (org-ml-parse-this-element)
(org-ml-get-property :value)
(org-ml-to-string))
=> "[2019-01-01 Tue]"
(:buffer "~learn to~")
(->> (org-ml-parse-this-object)
(org-ml-get-property :value))
=> "learn to"
(:buffer "# not here")
(->> (org-ml-parse-this-element)
(org-ml-get-property :value))
=> "not here"
(:buffer "#+begin_comment"
"not here"
"#+end_comment")
(->> (org-ml-parse-this-element)
(org-ml-get-property :value))
=> "not here"
(:buffer "%%(print :hi)")
(->> (org-ml-parse-this-element)
(org-ml-get-property :value))
=> '(print :hi)
(:buffer ":LOGBOOK:"
":END:")
(->> (org-ml-parse-this-element)
(org-ml-get-property :drawer-name))
=> "LOGBOOK"
(:buffer "#+begin: blockhead :cache no"
"#+end:")
(->> (org-ml-parse-this-element)
(org-ml-get-property :block-name))
=> "blockhead"
(->> (org-ml-parse-this-element)
(org-ml-get-property :arguments))
=> '(:cache no)
(:buffer "\\pi{}")
(->> (org-ml-parse-this-object)
(org-ml-get-property :name))
=> "pi"
(->> (org-ml-parse-this-object)
(org-ml-get-property :use-brackets-p))
=> t
;; TODO test org-src-preserve-indentation
=> (:buffer "#+begin_example -n"
"example.com"
"#+end_example")
(->> (org-ml-parse-this-element)
(org-ml-get-property :switches))
=> '("-n")
(->> (org-ml-parse-this-element)
(org-ml-get-property :value))
=> "example.com"
(:buffer "#+begin_export domestic"
"bullets, bombs, and bigotry"
"#+end_export")
(->> (org-ml-parse-this-element)
(org-ml-get-property :type))
;; TODO why capitalized?
=> "DOMESTIC"
(->> (org-ml-parse-this-element)
(org-ml-get-property :value))
=> "bullets, bombs, and bigotry\n"
(:buffer "@@back-end:value@@")
(->> (org-ml-parse-this-object)
(org-ml-get-property :back-end))
=> "back-end"
(->> (org-ml-parse-this-object)
(org-ml-get-property :value))
=> "value"
(:buffer ": fixed")
(->> (org-ml-parse-this-element)
(org-ml-get-property :value))
=> "fixed"
(:buffer "[fn:blacklabel] society")
(->> (org-ml-parse-this-element)
(org-ml-get-property :label))
=> "blacklabel"
;; TODO the priority should be parsable after "COMMENT"
(:buffer "** TODO [#A] COMMENT dummy :tmsu:ARCHIVE:"
""
"stuff")
(->> (org-ml-parse-this-element)
(org-ml-get-property :archivedp))
=> t
(->> (org-ml-parse-this-element)
(org-ml-get-property :commentedp))
=> t
(->> (org-ml-parse-this-element)
(org-ml-get-property :level))
=> 2
(->> (org-ml-parse-this-element)
(org-ml-get-property :pre-blank))
=> 1
(->> (org-ml-parse-this-element)
(org-ml-get-property :priority))
=> ?A
(->> (org-ml-parse-this-element)
(org-ml-get-property :tags))
=> '("tmsu")
(->> (org-ml-parse-this-element)
(org-ml-get-property :title))
=> '("dummy")
(->> (org-ml-parse-this-element)
(org-ml-get-property :todo-keyword))
=> "TODO"
(:buffer "* Footnotes")
(->> (org-ml-parse-this-element)
(org-ml-get-property :footnote-section-p))
=> t
(:buffer "call_ktulu[:cache no](x=4)[:exports results]")
(->> (org-ml-parse-this-object)
(org-ml-get-property :call))
=> "ktulu"
(->> (org-ml-parse-this-object)
(org-ml-get-property :inside-header))
=> '(:cache no)
(->> (org-ml-parse-this-object)
(org-ml-get-property :arguments))
=> '("x=4")
(->> (org-ml-parse-this-object)
(org-ml-get-property :end-header))
=> '(:exports results)
(:buffer "src_python[:cache no]{print \"yeah boi\"}")
(->> (org-ml-parse-this-object)
(org-ml-get-property :language))
=> "python"
(->> (org-ml-parse-this-object)
(org-ml-get-property :parameters))
=> '(:cache no)
(->> (org-ml-parse-this-object)
(org-ml-get-property :value))
=> "print \"yeah boi\""
(:buffer "- [@2] [X] tmsu :: thing")
(->> (org-ml-parse-this-item)
(org-ml-get-property :bullet))
=> '-
(->> (org-ml-parse-this-item)
(org-ml-get-property :checkbox))
=> 'on
(->> (org-ml-parse-this-item)
(org-ml-get-property :counter))
=> 2
(->> (org-ml-parse-this-item)
(org-ml-get-property :tag))
=> '("tmsu")
(:buffer "#+KEY: VAL")
(->> (org-ml-parse-this-element)
(org-ml-get-property :key))
=> "KEY"
(->> (org-ml-parse-this-element)
(org-ml-get-property :value))
=> "VAL"
(:buffer "\begin{env}"
"body"
"\end{env}")
(->> (org-ml-parse-this-element)
(org-ml-get-property :value))
=> (:buffer "\begin{env}"
"body"
"\end{env}")
(:buffer "$2+2=4$")
(->> (org-ml-parse-this-object)
(org-ml-get-property :value))
=> "$2+2=4$"
(:buffer "[[file:/dev/null]]")
(->> (org-ml-parse-this-object)
(org-ml-get-property :path))
=> "/dev/null"
(->> (org-ml-parse-this-object)
(org-ml-get-property :type))
=> "file"
(->> (org-ml-parse-this-object)
(org-ml-get-property :format))
=> 'bracket
(:buffer "{{{economics(x=4,y=2)}}}")
(->> (org-ml-parse-this-object)
(org-ml-get-property :key))
=> "economics"
(->> (org-ml-parse-this-object)
(org-ml-get-property :args))
=> '("x=4" "y=2")
(:buffer "* dummy"
":PROPERTIES:"
":KEY: VAL"
":END:")
(->> (org-ml-parse-this-headline)
(org-ml-headline-get-section)
(-first-item)
(org-ml-get-children)
(-first-item)
(org-ml-get-property :key))
=> "KEY"
(->> (org-ml-parse-this-headline)
(org-ml-headline-get-section)
(-first-item)
(org-ml-get-children)
(-first-item)
(org-ml-get-property :value))
=> "VAL"
(:buffer "* dummy"
"CLOSED: [2019-01-01 Tue]")
(->> (org-ml-parse-this-headline)
(org-ml-headline-get-section)
(-first-item)
(org-ml-get-property :closed)
(org-ml-to-string))
=> "[2019-01-01 Tue]"
(:buffer "#+BEGIN_special"
"#+END_special")
(->> (org-ml-parse-this-element)
(org-ml-get-property :type))
=> "special"
(:buffer "#+begin_src emacs -n :cache no"
" (print 'hi)"
"#+end_src")
(->> (org-ml-parse-this-element)
(org-ml-get-property :language))
=> "emacs"
(->> (org-ml-parse-this-element)
(org-ml-get-property :value))
;; TODO why indented?
=> " (print 'hi)"
(->> (org-ml-parse-this-element)
(org-ml-get-property :parameters))
=> '(:cache no)
(->> (org-ml-parse-this-element)
(org-ml-get-property :switches))
=> '("-n")
(:buffer "* dummy [50%]")
(->> (org-ml-parse-this-headline)
(org-ml-headline-get-statistics-cookie)
(org-ml-get-property :value))
=> '(50)
(:buffer "sub_{woofer}")
(->> (org-ml-parse-object-at 6)
(org-ml-get-property :use-brackets-p))
=> t
(:buffer "super_{woofer}")
(->> (org-ml-parse-object-at 8)
(org-ml-get-property :use-brackets-p))
=> t
(:buffer "| a |"
"#+TBLFM: x=$2")
(->> (org-ml-parse-this-element)
(org-ml-get-property :tblfm))
=> '("x=$2")
(:buffer "<<found>>")
(->> (org-ml-parse-this-object)
(org-ml-get-property :value))
=> "found"
(:buffer "<2020-02-02 Sun 12:00 +1d -1d>--<2020-02-03 Mon 12:00 +1d -1d>")
(->> (org-ml-parse-this-object)
(org-ml-get-property :year-start))
=> 2020
(->> (org-ml-parse-this-object)
(org-ml-get-property :month-start))
=> 2
(->> (org-ml-parse-this-object)
(org-ml-get-property :day-start))
=> 2
(->> (org-ml-parse-this-object)
(org-ml-get-property :hour-start))
=> 12
(->> (org-ml-parse-this-object)
(org-ml-get-property :minute-start))
=> 0
(->> (org-ml-parse-this-object)
(org-ml-get-property :year-end))
=> 2020
(->> (org-ml-parse-this-object)
(org-ml-get-property :month-end))
=> 2
(->> (org-ml-parse-this-object)
(org-ml-get-property :day-end))
=> 3
(->> (org-ml-parse-this-object)
(org-ml-get-property :hour-end))
=> 12
(->> (org-ml-parse-this-object)
(org-ml-get-property :minute-end))
=> 0
(->> (org-ml-parse-this-object)
(org-ml-get-property :type))
=> 'active-range
(->> (org-ml-parse-this-object)
(org-ml-get-property :warning-type))
=> 'all
(->> (org-ml-parse-this-object)
(org-ml-get-property :warning-unit))
=> 'day
(->> (org-ml-parse-this-object)
(org-ml-get-property :warning-value))
=> 1
(->> (org-ml-parse-this-object)
(org-ml-get-property :repeater-type))
=> 'cumulate
(->> (org-ml-parse-this-object)
(org-ml-get-property :repeater-unit))
=> 'day
(->> (org-ml-parse-this-object)
(org-ml-get-property :repeater-value))
=> 1
(:buffer "=I am not a crook=")
(->> (org-ml-parse-this-object)
(org-ml-get-property :value))
=> "I am not a crook"
(:buffer "*postable* ")
(->> (org-ml-parse-this-object)
(org-ml-get-property :post-blank))
=> 1
(:buffer "/*child*/")
(->> (org-ml-parse-this-object)
(org-ml-get-children)
(car)
(org-ml-get-property :parent)
(org-ml-to-trimmed-string))
=> "/*child*/"
(:buffer "/16-chars-long/")
(->> (org-ml-parse-this-object)
(org-ml-get-property :begin))
=> 1
(->> (org-ml-parse-this-object)
(org-ml-get-property :contents-begin))
=> 2
(->> (org-ml-parse-this-object)
(org-ml-get-property :contents-end))
=> 15
(->> (org-ml-parse-this-object)
(org-ml-get-property :end))
=> 16
;; affiliated keywords
(:buffer "#+name: name"
"#+attr_foo: bar"
"#+attr_foo: BAR"
"#+plot: poo"
"#+caption: koo"
"#+caption[COO]: KOO"
"#+results[hash]: res"
"#+header: :k1 h1"
"#+header: :k2 h2"
"#+begin_src"
"echo test for echo"
"#+end_src")
(->> (org-ml-parse-this-element)
(org-ml-get-property :name))
=> "name"
(->> (org-ml-parse-this-element)
(org-ml-get-property :plot))
=> "poo"
(->> (org-ml-parse-this-element)
(org-ml-get-property :attr_foo))
=> '("bar" "BAR")
(->> (org-ml-parse-this-element)
(org-ml-get-property :header))
=> '((:k1 "h1") (:k2 "h2"))
(->> (org-ml-parse-this-element)
(org-ml-get-property :results))
=> '("hash" "res")
(->> (org-ml-parse-this-element)
(org-ml-get-property :caption))
=> '("koo" ("COO" "KOO"))
:end-hidden
(:buffer "* not arguable")
(:comment "Throw error when requesting a property that doesn't exist")
(->> (org-ml-parse-this-headline)
(org-ml-get-property :value))
!!> arg-type-error)
(defexamples-content org-ml-map-property
nil
:begin-hidden
(:buffer "#+call: ktulu()")
(org-ml->> (org-ml-parse-this-element)
(org-ml-map-property :call #'s-upcase)
(org-ml-to-trimmed-string))
=> "#+call: KTULU()"
(:buffer "CLOCK: [2019-01-01 Tue 12:00]")
(org-ml->> (org-ml-parse-this-element)
(org-ml-map-property* :value (org-ml-timestamp-shift-end 1 'hour it))
(org-ml-to-trimmed-string))
=> "CLOCK: [2019-01-01 Tue 12:00]--[2019-01-01 Tue 13:00] => 1:00"
:end-hidden
(:buffer "~learn to~")
(org-ml->> (org-ml-parse-this-object)
(org-ml-map-property :value #'s-upcase)
(org-ml-to-trimmed-string))
=> "~LEARN TO~"
(:comment "Throw error if property doesn't exist")
(org-ml->> (org-ml-parse-this-object)
(org-ml-map-property :title #'s-upcase)
(org-ml-to-trimmed-string))
!!> arg-type-error
(:comment "Throw error if function doesn't return proper type")
(org-ml->> (org-ml-parse-this-object)
(org-ml-map-property* :value (if it 1 0))
(org-ml-to-trimmed-string))
!!> arg-type-error
:begin-hidden
(:buffer "# not here")
(org-ml->> (org-ml-parse-this-element)
(org-ml-map-property :value #'s-upcase)
(org-ml-to-trimmed-string))
=> "# NOT HERE"
(:buffer "#+begin_comment"
"not here"
"#+end_comment")
(org-ml->> (org-ml-parse-this-element)
(org-ml-map-property :value #'s-upcase)
(org-ml-to-trimmed-string))
=> (:result "#+begin_comment"
"NOT HERE"
"#+end_comment")
(:buffer "%%(diary-float t 1 -1)")
(org-ml->> (org-ml-parse-this-element)
(org-ml-map-property :value (org-ml--map-last* (+ 2 it) it))
(org-ml-to-trimmed-string))
=> (:buffer "%%(diary-float t 1 1)")
(:buffer ":LOGBOOK:"
":END:")
(org-ml->> (org-ml-parse-this-element)
(org-ml-map-property :drawer-name #'s-capitalize)
(org-ml-to-trimmed-string))
=> (:result ":Logbook:"
":END:")
(:buffer "#+begin: blockhead"
"#+end:")
(org-ml->> (org-ml-parse-this-element)
(org-ml-map-property :block-name #'s-upcase)
(org-ml-to-trimmed-string))
=> (:result "#+begin: BLOCKHEAD"
"#+end:")
;; TODO add entity
(:buffer "#+begin_example"
"example.com"
"#+end_example")
(org-ml->> (org-ml-parse-this-element)
(org-ml-map-property* :value (concat "https://" it))
(org-ml-to-trimmed-string))
=> (:result "#+begin_example"
" https://example.com"
"#+end_example")
(:buffer "#+begin_export domestic"
"bullets, bombs, and bigotry"
"#+end_export")
(org-ml->> (org-ml-parse-this-element)
(org-ml-map-property :type #'s-upcase)
(org-ml-map-property :value #'s-upcase)
(org-ml-to-trimmed-string))
=> (:result "#+begin_export DOMESTIC"
"BULLETS, BOMBS, AND BIGOTRY"
"#+end_export")
(:buffer "@@back-end:value@@")
(org-ml->> (org-ml-parse-this-object)
(org-ml-map-property :back-end #'s-upcase)
(org-ml-map-property :value #'s-upcase)
(org-ml-to-trimmed-string))
=> "@@BACK-END:VALUE@@"
(:buffer ": fixed")
(org-ml->> (org-ml-parse-this-element)
(org-ml-map-property :value #'s-upcase)
(org-ml-to-trimmed-string))
=> ": FIXED"
(:buffer "[fn:blacklabel] society")
(org-ml->> (org-ml-parse-this-element)
(org-ml-map-property :label #'s-upcase)
(org-ml-to-trimmed-string))
=> "[fn:BLACKLABEL] society"
(:buffer "* headline")
(org-ml->> (org-ml-parse-this-headline)
(org-ml-map-property* :title (-map #'s-upcase it))
(org-ml-to-trimmed-string))
=> "* HEADLINE"
(:buffer "call_ktulu()")
(org-ml->> (org-ml-parse-this-object)
(org-ml-map-property :call #'s-upcase)
(org-ml-to-trimmed-string))
=> "call_KTULU()"
(:buffer "src_python{print \"hi\"}")
(org-ml->> (org-ml-parse-this-object)
(org-ml-map-property* :value (s-replace-regexp "\".*\"" #'s-upcase it))
(org-ml-to-trimmed-string))
=> "src_python{print \"HI\"}"
(:buffer "- tag :: thing")
(org-ml->> (org-ml-parse-this-item)
(org-ml-map-property :tag (lambda (it) (-map #'s-upcase it)))
(org-ml-to-trimmed-string))
=> "- TAG :: thing"
(:buffer "#+key: VAL")
(org-ml->> (org-ml-parse-this-element)
(org-ml-map-property :key (-partial #'s-prepend "OM_"))
(org-ml-map-property :value (-partial #'s-prepend "OM_"))
(org-ml-to-trimmed-string))
=> "#+om_key: OM_VAL"
;; TODO add examples for latex frag/env
(:buffer "[[https://downloadmoreram.org][legit]]")
(org-ml->> (org-ml-parse-this-object)
(org-ml-map-property* :path (s-replace ".org" ".com" it))
(org-ml-to-trimmed-string))
=> "[[https://downloadmoreram.com][legit]]"
(:buffer "{{{economics}}}")
(org-ml->> (org-ml-parse-this-object)
(org-ml-map-property :key #'s-upcase)
(org-ml-to-trimmed-string))
=> "{{{ECONOMICS}}}"
(:buffer "* dummy"
":PROPERTIES:"
":KEY: VAL"
":END:")
(org-ml->> (org-ml-parse-this-headline)
(org-ml-headline-get-section)
(-first-item)
(org-ml-get-children)
(-first-item)
(org-ml-map-property :key (-partial #'s-prepend "OM_"))
(org-ml-map-property :value (-partial #'s-prepend "OM_"))
(org-ml-to-trimmed-string))
=> ":OM_KEY: OM_VAL"
;; TODO add example for planning
(:buffer "#+begin_special"
"#+end_special")
(org-ml->> (org-ml-parse-this-element)
(org-ml-map-property :type #'s-upcase)
(org-ml-to-trimmed-string))
=> (:result "#+begin_SPECIAL"
"#+end_SPECIAL")
;; TODO add example for src block
;; TODO add example for statistics cookie
(:buffer "<<found>>")
(org-ml->> (org-ml-parse-this-object)
(org-ml-map-property :value #'s-upcase)
(org-ml-to-trimmed-string))
=> "<<FOUND>>"
(:buffer "=I am not a crook=")
(org-ml->> (org-ml-parse-this-object)
(org-ml-map-property :value #'s-upcase)
(org-ml-to-trimmed-string))
=> "=I AM NOT A CROOK="
:end-hidden)
(defexamples-content org-ml-toggle-property
nil
(:buffer "\\pi")
(org-ml->> (org-ml-parse-this-object)
(org-ml-toggle-property :use-brackets-p)
(org-ml-to-trimmed-string))
=> "\\pi{}"
;; TODO test src/example block preserve indent
:begin-hidden
(:buffer "* headline")
(org-ml->> (org-ml-parse-this-headline)
(org-ml-toggle-property :archivedp)
(org-ml-to-trimmed-string))
=> "* headline :ARCHIVE:"
(org-ml->> (org-ml-parse-this-headline)
(org-ml-toggle-property :commentedp)
(org-ml-to-trimmed-string))
=> "* COMMENT headline"
(org-ml->> (org-ml-parse-this-headline)
(org-ml-toggle-property :footnote-section-p)
(org-ml-to-trimmed-string))
=> "* Footnotes"
(:buffer "sub_woofer")
(org-ml->> (org-ml-parse-object-at 5)
(org-ml-toggle-property :use-brackets-p)
(org-ml-to-trimmed-string))
=> "_{woofer}"
(:buffer "super^woofer")
(org-ml->> (org-ml-parse-object-at 7)
(org-ml-toggle-property :use-brackets-p)
(org-ml-to-trimmed-string))
=> "^{woofer}"
:end-hidden
(:buffer "- [ ] nope")
(:comment "Throw an error when trying to toggle a non-boolean property")
(org-ml->> (org-ml-parse-this-item)
(org-ml-toggle-property :checkbox)
(org-ml-to-trimmed-string))
!!> arg-type-error)
(defexamples-content org-ml-shift-property
nil
(:buffer "* no priorities")
(:comment "Do nothing if there is nothing to shift.")
(org-ml->> (org-ml-parse-this-headline)
(org-ml-shift-property :priority 1)
(org-ml-to-trimmed-string))
=> "* no priorities"
(:buffer "* [#A] priorities")
(org-ml->> (org-ml-parse-this-headline)
(org-ml-shift-property :priority -1)
(org-ml-to-trimmed-string))
=> "* [#B] priorities"
(:comment "Wrap priority around when crossing the min or max")
(org-ml->> (org-ml-parse-this-headline)
(org-ml-shift-property :priority 1)
(org-ml-to-trimmed-string))
=> "* [#C] priorities"
:begin-hidden
(org-ml->> (org-ml-parse-this-headline)
(org-ml-shift-property :priority -2)
(org-ml-to-trimmed-string))
=> "* [#C] priorities"
:end-hidden
(:buffer "* TODO or not todo")
(:comment "Throw error when shifting an unshiftable property")
(org-ml->> (org-ml-parse-this-headline)
(org-ml-shift-property :todo-keyword 1)
(org-ml-to-string))
!!> arg-type-error
:begin-hidden
(:buffer "*bold*")
(org-ml->> (org-ml-parse-this-object)
(org-ml-shift-property :post-blank 1)
(org-ml-to-string))
=> "*bold* "
(org-ml->> (org-ml-parse-this-object)
(org-ml-shift-property :post-blank -1)
(org-ml-to-string))
=> "*bold*"
(:buffer "1. thing")
(org-ml->> (org-ml-parse-this-item)
(org-ml-shift-property :counter 1)
(org-ml-to-trimmed-string))
=> "1. thing"
(:buffer "1. [@1] thing")
(org-ml->> (org-ml-parse-this-item)
(org-ml-shift-property :counter 1)
(org-ml-to-trimmed-string))
=> "1. [@2] thing"
(org-ml->> (org-ml-parse-this-item)
(org-ml-shift-property :counter -1)
(org-ml-to-trimmed-string))
=> "1. [@1] thing"
(:buffer "* noob level")
(org-ml->> (org-ml-parse-this-headline)
(org-ml-shift-property :level 1)
(org-ml-to-trimmed-string))
=> "** noob level"
(:comment "Do nothing when final value is less than one.")
(org-ml->> (org-ml-parse-this-headline)
(org-ml-shift-property :level -1)
(org-ml-to-trimmed-string))
=> "* noob level"
(:buffer "* headline"
"stuff")
(org-ml->> (org-ml-parse-this-headline)
(org-ml-shift-property :pre-blank 1)
(org-ml-to-trimmed-string))
=> (:result "* headline"
""
"stuff")
(org-ml->> (org-ml-parse-this-headline)
(org-ml-shift-property :pre-blank -1)
(org-ml-to-trimmed-string))
=> (:result "* headline"
"stuff")
:end-hidden)
(defexamples-content org-ml-insert-into-property
nil
(:buffer "#+call: ktulu(y=1)")
(org-ml->> (org-ml-parse-this-element)
(org-ml-insert-into-property :arguments 0 "x=4")
(org-ml-to-trimmed-string))
=> "#+call: ktulu(x=4,y=1)"
(:comment "Do nothing if the string is already in the list")
(org-ml->> (org-ml-parse-this-element)
(org-ml-insert-into-property :arguments 0 "y=1")
(org-ml-to-trimmed-string))
=> "#+call: ktulu(y=1)"
(:comment "Throw error when inserting into a property that is not a list of strings")
(org-ml->> (org-ml-parse-this-element)
(org-ml-insert-into-property :end-header 0 "html")
(org-ml-to-trimmed-string))
!!> arg-type-error
:begin-hidden
(:buffer "* headline :tag1:")
(org-ml->> (org-ml-parse-this-headline)
(org-ml-insert-into-property :tags 0 "tag0")
(org-ml-to-trimmed-string))
=> "* headline :tag0:tag1:"
(:buffer "#+begin_example -n"
"#+end_example")
(org-ml->> (org-ml-parse-this-element)
(org-ml-insert-into-property :switches -1 "-r")
(org-ml-to-trimmed-string))
=> (:result "#+begin_example -n -r"
"#+end_example")
(:buffer "call_ktulu(y=1)")
(org-ml->> (org-ml-parse-this-object)
(org-ml-insert-into-property :arguments 0 "x=4")
(org-ml-to-trimmed-string))
=> "call_ktulu(x=4,y=1)"
(:buffer "{{{economics(x=4)}}}")
(org-ml->> (org-ml-parse-this-object)
(org-ml-insert-into-property :args 0 "z=2")
(org-ml-to-trimmed-string))
=> "{{{economics(z=2,x=4)}}}"
(:buffer "#+begin_src emacs-lisp -n"
"#+end_src")
(org-ml->> (org-ml-parse-this-element)
(org-ml-insert-into-property :switches -1 "-r")
(org-ml-to-trimmed-string))
=> (:result "#+begin_src emacs-lisp -n -r"
"#+end_src")
(:buffer "| a |"
"#+TBLFM: x=$2")
(org-ml->> (org-ml-parse-this-element)
(org-ml-insert-into-property :tblfm -1 "y=$3")
(org-ml-to-trimmed-string))
=> (:result "| a |"
"#+TBLFM: y=$3"
"#+TBLFM: x=$2")
:end-hidden)
(defexamples-content org-ml-remove-from-property
nil
(:buffer "#+call: ktulu(y=1)")
(org-ml->> (org-ml-parse-this-element)
(org-ml-remove-from-property :arguments "y=1")
(org-ml-to-trimmed-string))
=> "#+call: ktulu()"
(:comment "Do nothing if the string does not exist")
(org-ml->> (org-ml-parse-this-element)
(org-ml-remove-from-property :arguments "d=666")
(org-ml-to-trimmed-string))
=> "#+call: ktulu(y=1)"
(:comment "Throw error when removing from property that is not a string list")
(org-ml->> (org-ml-parse-this-element)
(org-ml-remove-from-property :end-header ":results")
(org-ml-to-trimmed-string))
!!> arg-type-error
:begin-hidden
(:buffer "* headline :tag1:")
(org-ml->> (org-ml-parse-this-headline)
(org-ml-remove-from-property :tags "tag1")
(org-ml-to-trimmed-string))
=> "* headline"
(:buffer "#+begin_example -n"
"#+end_example")
(org-ml->> (org-ml-parse-this-element)
(org-ml-remove-from-property :switches "-n")
(org-ml-to-trimmed-string))
=> (:result "#+begin_example"
"#+end_example")
(:buffer "call_ktulu(y=1)")
(org-ml->> (org-ml-parse-this-object)
(org-ml-remove-from-property :arguments "y=1")
(org-ml-to-trimmed-string))
=> "call_ktulu()"
(:buffer "{{{economics(x=4)}}}")
(org-ml->> (org-ml-parse-this-object)
(org-ml-remove-from-property :args "x=4")
(org-ml-to-trimmed-string))
=> "{{{economics}}}"
(:buffer "#+begin_src emacs-lisp -n"
"#+end_src")
(org-ml->> (org-ml-parse-this-element)
(org-ml-remove-from-property :switches "-n")
(org-ml-to-trimmed-string))
=> (:result "#+begin_src emacs-lisp"
"#+end_src")
(:buffer "| a |"
"#+TBLFM: x=$2")
(org-ml->> (org-ml-parse-this-element)
(org-ml-remove-from-property :tblfm "x=$2")
(org-ml-to-trimmed-string))
=> "| a |"
:end-header)
(defexamples-content org-ml-plist-put-property
nil
(:buffer "#+call: ktulu[:cache no]()")
(org-ml->> (org-ml-parse-this-element)
(org-ml-plist-put-property :end-header :results 'html)
(org-ml-to-trimmed-string))
=> "#+call: ktulu[:cache no]() :results html"
(:comment "Change the value of key if it already is present")
(org-ml->> (org-ml-parse-this-element)
(org-ml-plist-put-property :inside-header :cache 'yes)
(org-ml-to-trimmed-string))
=> "#+call: ktulu[:cache yes]()"
(:comment "Do nothing if the key and value already exist")
(org-ml->> (org-ml-parse-this-element)
(org-ml-plist-put-property :inside-header :cache 'no)
(org-ml-to-trimmed-string))
=> "#+call: ktulu[:cache no]()"
(:comment "Throw error if setting property that isn't a plist")
(org-ml->> (org-ml-parse-this-element)
(org-ml-plist-put-property :arguments :cache 'no)
(org-ml-to-trimmed-string))
!!> arg-type-error
:begin-hidden
(:buffer "#+begin: blockhead :format \"[%s]\""
"#+end:")
(org-ml->> (org-ml-parse-this-element)
(org-ml-plist-put-property :arguments :format "<%s>")
(org-ml-to-trimmed-string))
=> (:result "#+begin: blockhead :format \"<%s>\""
"#+end:")
(:buffer "call_ktulu[:cache no]()")
(org-ml->> (org-ml-parse-this-object)
(org-ml-plist-put-property :inside-header :cache 'yes)
(org-ml-plist-put-property :end-header :results 'html)
(org-ml-to-trimmed-string))
=> "call_ktulu[:cache yes]()[:results html]"
(:buffer "src_emacs-lisp[:exports results]{}")
(org-ml->> (org-ml-parse-this-object)
(org-ml-plist-put-property :parameters :exports 'both)
(org-ml-to-trimmed-string))
=> "src_emacs-lisp[:exports both]{}"
(:buffer "#+begin_src emacs-lisp -n :exports results"
"#+end_src")
(org-ml->> (org-ml-parse-this-element)
(org-ml-plist-put-property :parameters :exports 'both)
(org-ml-to-trimmed-string))
=> (:result "#+begin_src emacs-lisp -n :exports both"
"#+end_src")
:end-hidden)
(defexamples-content org-ml-plist-remove-property
nil
(:buffer "#+call: ktulu() :results html")
(org-ml->> (org-ml-parse-this-element)
(org-ml-plist-remove-property :end-header :results)
(org-ml-to-trimmed-string))
=> "#+call: ktulu()"
(:comment "Do nothing if the key is not present")
(org-ml->> (org-ml-parse-this-element)
(org-ml-plist-remove-property :inside-header :cache)
(org-ml-to-trimmed-string))
=> "#+call: ktulu() :results html"
(:comment "Throw error if trying to remove key from non-plist property")
(org-ml->> (org-ml-parse-this-element)
(org-ml-plist-remove-property :arguments :cache)
(org-ml-to-trimmed-string))
!!> arg-type-error
:begin-hidden
(:buffer "#+begin: blockhead :format \"[%s]\""
"#+end:")
(org-ml->> (org-ml-parse-this-element)
(org-ml-plist-remove-property :arguments :format)
(org-ml-to-trimmed-string))
=> (:result "#+begin: blockhead"
"#+end:")
(:buffer "call_ktulu[:cache no]()[:results html]")
(org-ml->> (org-ml-parse-this-object)
(org-ml-plist-remove-property :inside-header :cache)
(org-ml-plist-remove-property :end-header :results)
(org-ml-to-trimmed-string))
=> "call_ktulu()"
(:buffer "src_emacs-lisp[:exports results]{}")
(org-ml->> (org-ml-parse-this-object)
(org-ml-plist-remove-property :parameters :exports)
(org-ml-to-trimmed-string))
=> "src_emacs-lisp{}"
(:buffer "#+begin_src emacs-lisp -n :exports results"
"#+end_src")
(org-ml->> (org-ml-parse-this-element)
(org-ml-plist-remove-property :parameters :exports)
(org-ml-to-trimmed-string))
=> (:result "#+begin_src emacs-lisp -n"
"#+end_src")
:end-hidden)
;; (defexamples-content org-ml-property-is-nil-p
;; nil
;; (:buffer "* TODO dummy")
;; (->> (org-ml-parse-this-headline)
;; (org-ml-property-is-nil-p :todo-keyword))
;; => nil
;; (->> (org-ml-parse-this-headline)
;; (org-ml-property-is-nil-p :commentedp))
;; => t)
;; (defexamples-content org-ml-property-is-non-nil-p
;; nil
;; (:buffer "* TODO dummy")
;; (->> (org-ml-parse-this-headline)
;; (org-ml-property-is-non-nil-p :todo-keyword))
;; => t
;; (->> (org-ml-parse-this-headline)
;; (org-ml-property-is-non-nil-p :commentedp))
;; => nil)
;; (defexamples-content org-ml-property-is-eq-p
;; nil
;; (:buffer "* [#A] dummy")
;; (->> (org-ml-parse-this-headline)
;; (org-ml-property-is-eq-p :priority ?A))
;; => t
;; (->> (org-ml-parse-this-headline)
;; (org-ml-property-is-eq-p :priority ?B))
;; => nil)
;; (defexamples-content org-ml-property-is-equal-p
;; nil
;; (:buffer "* TODO dummy")
;; (->> (org-ml-parse-this-headline)
;; (org-ml-property-is-equal-p :todo-keyword "TODO"))
;; => t
;; (->> (org-ml-parse-this-headline)
;; (org-ml-property-is-equal-p :todo-keyword "DONE"))
;; => nil)
;; (defexamples-content org-ml-property-is-predicate-p
;; nil
;; (:buffer "* this is a dummy")
;; (->> (org-ml-parse-this-headline)
;; (org-ml-property-is-predicate-p*
;; :title (s-contains? "dummy" (car it))))
;; => t)
(defexamples-content org-ml-get-properties
nil
(:buffer "call_ktulu[:cache no](x=4)[:exports results]")
(->> (org-ml-parse-this-object)
(org-ml-get-properties '(:call :inside-header :arguments :end-header)))
=> '("ktulu" (:cache no) ("x=4") (:exports results)))
(defexamples-content org-ml-get-all-properties
nil
(:buffer "*bold*")
(--> (org-ml-parse-this-object)
(org-ml-get-all-properties it)
(plist-put it :buffer nil)
(plist-put it :parent nil))
=> (list :begin 1
:post-affiliated nil
:contents-begin 2
:contents-end 6
:end 7
:post-blank 0
:secondary nil
:mode nil
:granularity nil
:cached nil
:org-element--cache-sync-key nil
:robust-begin nil
:robust-end nil
:true-level nil
:buffer nil
:deferred nil
:structure nil
:parent nil))
(defexamples-content org-ml-set-properties
nil
(:buffer "- thing")
(org-ml->> (org-ml-parse-this-item)
(org-ml-set-properties (list :bullet 1
:checkbox 'on
:counter 2
:tag '("tmsu")))
(org-ml-to-trimmed-string))
=> "1. [@2] [X] tmsu :: thing"
(:buffer "- plain")
(org-ml->> (org-ml-parse-this-element)
(org-ml-set-properties (list :name "plain name"
:attr_XXX '("tmsu")))
(org-ml-to-trimmed-string))
=> (:result "#+name: plain name"
"#+attr_xxx: tmsu"
"- plain"))
(defexamples-content org-ml-map-properties
nil
(:buffer "#+KEY: VAL")
(org-ml->> (org-ml-parse-this-element)
(org-ml-map-properties
(list :key (-partial #'s-prepend "OM_")
:value (-partial #'s-prepend "OM_")))
(org-ml-to-trimmed-string))
=> "#+om_key: OM_VAL"
(:comment "Throw error if any of the properties are invalid")
(org-ml->> (org-ml-parse-this-element)
(org-ml-map-properties*
(:title (s-prepend "OM_" it) :value (s-prepend "OM_" it)))
(org-ml-to-trimmed-string))
!!> error
)
(defexamples-content org-ml-get-parents
nil
(:buffer "* one"
"** two"
"*** three")
(->> (org-ml-parse-this-subtree)
(org-ml-get-parents)
(--map (org-ml-get-property :begin it)))
=> '(1)
(->> (org-ml-parse-this-subtree)
(org-ml-headline-get-subheadlines)
(car)
(org-ml-headline-get-subheadlines)
(car)
(org-ml-get-parents)
(--map (org-ml-get-property :begin it)))
=> '(1 7 14))
(defexamples-content org-ml-remove-parent
nil
(:buffer "one")
(:comment "This is actually a paragraph node, but parsing the object"
"will directly return a plain-text node with the :parent"
"pointing to the paragraph")
(org-ml->> (org-ml-parse-this-object)
(org-ml-remove-parent))
=> "one"
(defexamples-content org-ml-remove-parents
nil
(:buffer "one")
(org-ml->> (org-ml-parse-this-element)
(org-ml-remove-parents))
=> '(paragraph
(:begin 1 :end 4 :contents-begin 1 :contents-end 4 :post-blank 0 :post-affiliated 1 :parent nil)
"one"))
(:buffer "* headline")
(org-ml->> (org-ml-parse-this-element)
(org-ml-remove-parents)
(org-ml-get-property :parent))
=> nil
(:buffer "- tag :: thingy")
(org-ml->> (org-ml-parse-this-item)
(org-ml-remove-parents)
(org-ml-get-children)
(car)
(org-ml-get-property :parent))
nil
:begin-hidden
;; for some reason the timestamps in planning don't have parents
(:buffer "* headline"
"SCHEDULED: <2021-08-27 Fri>")
(->> (org-ml-parse-this-element)
(org-ml-headline-get-planning)
(org-ml-get-property :scheduled)
;; (org-ml-remove-parents)
(org-ml-get-property :parent)
=> nil)
;; same thing with clocks...
(:buffer "* headline"
"CLOCK: [2021-08-27 Fri 23:31]--[2021-08-28 Sat 00:45] => 1:14")
(->> (org-ml-parse-this-element)
(org-ml-headline-get-logbook-clocks nil)
(car)
(org-ml-get-property :value)
(org-ml-get-property :parent)
=> nil)
:end-hidden
))
(def-example-subgroup "Clock"
nil
(defexamples-content org-ml-clock-is-running
nil
(:buffer "CLOCK: [2019-01-01 Tue 00:00]")
(->> (org-ml-parse-this-element)
(org-ml-clock-is-running))
=> t
(:buffer "CLOCK: [2019-01-01 Tue 00:00]--[2019-01-02 Wed 00:00] => 24:00")
(->> (org-ml-parse-this-element)
(org-ml-clock-is-running))
=> nil))
(def-example-subgroup "Entity"
nil
(defexamples-content org-ml-entity-get-replacement
nil
(:buffer "\\pi{}")
(->> (org-ml-parse-this-object)
(org-ml-entity-get-replacement :latex))
=> "\\pi"
(->> (org-ml-parse-this-object)
(org-ml-entity-get-replacement :latex-math-p))
=> t
(->> (org-ml-parse-this-object)
(org-ml-entity-get-replacement :html))
=> "π"
(->> (org-ml-parse-this-object)
(org-ml-entity-get-replacement :ascii))
=> "pi"
(->> (org-ml-parse-this-object)
(org-ml-entity-get-replacement :latin1))
=> "pi"
(->> (org-ml-parse-this-object)
(org-ml-entity-get-replacement :utf-8))
=> "π"))
(def-example-subgroup "Headline"
nil
(defexamples-content org-ml-headline-set-title!
nil
(:buffer "* really impressive title")
(org-ml->> (org-ml-parse-this-headline)
(org-ml-headline-set-title! "really *impressive* title" '(2 3))
(org-ml-to-trimmed-string))
=> "* really *impressive* title [2/3]")
(defexamples-content org-ml-headline-is-done
nil
(:buffer "* TODO darn")
(->> (org-ml-parse-this-headline)
(org-ml-headline-is-done))
=> nil
(:buffer "* DONE yay")
(->> (org-ml-parse-this-headline)
(org-ml-headline-is-done))
=> t)
(defexamples-content org-ml-headline-has-tag
nil
(:buffer "* dummy")
(->> (org-ml-parse-this-headline)
(org-ml-headline-has-tag "tmsu"))
=> nil
(:buffer "* dummy :tmsu:")
(->> (org-ml-parse-this-headline)
(org-ml-headline-has-tag "tmsu"))
=> t)
(defexampl
gitextract_xakltvns/ ├── .emacs/ │ ├── 28.2/ │ │ └── straight/ │ │ └── versions/ │ │ └── default.el │ ├── 29.3/ │ │ └── straight/ │ │ └── versions/ │ │ └── default.el │ └── 30.1/ │ └── straight/ │ └── versions/ │ └── default.el ├── .github/ │ └── workflows/ │ └── test.yml ├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── Makefile ├── README.md ├── bench/ │ ├── org-ml-bench-fw.el │ └── org-ml-benchmarks.el ├── dev/ │ ├── org-ml-cookbook.el │ ├── org-ml-docs.el │ ├── org-ml-examples.el │ ├── org-ml-test-common.el │ ├── org-ml-test-external.el │ └── org-ml-test-internal.el ├── docs/ │ ├── api-reference.md │ └── cookbook.md ├── env-28.2.yml ├── env-29.3.yml ├── env-30.1.yml ├── init.el ├── org-ml-macs.el └── org-ml.el
Condensed preview — 25 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (1,112K chars).
[
{
"path": ".emacs/28.2/straight/versions/default.el",
"chars": 613,
"preview": "((\"dash.el\" . \"721436b04da4e2795387cb48a98ac6de37ece0fd\")\n (\"el-get\" . \"f220df34333fdb363b84b28f4ed4a5575341bf45\")\n (\"em"
},
{
"path": ".emacs/29.3/straight/versions/default.el",
"chars": 613,
"preview": "((\"dash.el\" . \"721436b04da4e2795387cb48a98ac6de37ece0fd\")\n (\"el-get\" . \"f220df34333fdb363b84b28f4ed4a5575341bf45\")\n (\"em"
},
{
"path": ".emacs/30.1/straight/versions/default.el",
"chars": 613,
"preview": "((\"dash.el\" . \"721436b04da4e2795387cb48a98ac6de37ece0fd\")\n (\"el-get\" . \"f220df34333fdb363b84b28f4ed4a5575341bf45\")\n (\"em"
},
{
"path": ".github/workflows/test.yml",
"chars": 380,
"preview": "name: CI\non: [push]\n\njobs:\n build:\n runs-on: ubuntu-latest\n strategy:\n matrix:\n emacs_version:\n "
},
{
"path": ".gitignore",
"chars": 86,
"preview": "*.elc\n.emacs/*/straight/build\n.emacs/*/straight/repos\n.emacs/*/straight/build-cache.el"
},
{
"path": "CHANGELOG.md",
"chars": 6475,
"preview": "# Changelog\n\n## 6.0.2\n\n- fix org-ml-match-do* form bug\n\n## 6.0.1\n\n- add tests for emacs 30.1\n\n## 6.0.0\n\nThis is a major "
},
{
"path": "LICENSE",
"chars": 35147,
"preview": " GNU GENERAL PUBLIC LICENSE\n Version 3, 29 June 2007\n\n Copyright (C) 2007 Free "
},
{
"path": "Makefile",
"chars": 1503,
"preview": "EMACS ?= emacs -Q --batch --load init.el -L .\nRM ?= rm -f\n\nall: test\n\n# run all tests with both interpreted and compiled"
},
{
"path": "README.md",
"chars": 18509,
"preview": "# org-ml   2020 Free Softwa"
},
{
"path": "bench/org-ml-benchmarks.el",
"chars": 8526,
"preview": ";;; org-ml-benchmarks.el --- Benchmarks for org-ml -*- lexical-binding: t; -*-\n\n;; Copyright (C) 2020 Free Software Foun"
},
{
"path": "dev/org-ml-cookbook.el",
"chars": 1413,
"preview": ";;; org-ml-cookbook.el --- Common patterns for org.el's -*- lexical-binding: t -*-\n\n;; Copyright (C) 2015 Free Software"
},
{
"path": "dev/org-ml-docs.el",
"chars": 16450,
"preview": ";;; org-ml-docs.el --- Extract org-ml's docs -*- lexical-binding: t; -*-\n\n;; Copyright (C) 2015 Free Software Foundation"
},
{
"path": "dev/org-ml-examples.el",
"chars": 234876,
"preview": ";;; org-ml-examples.el --- Examples for org.el's API -*- lexical-binding: t -*-\n\n;; Copyright (C) 2015 Free Software Fo"
},
{
"path": "dev/org-ml-test-common.el",
"chars": 3701,
"preview": ";;; org-ml-test-common.el --- Common Test functions -*- lexical-binding: t; -*-\n\n;; Copyright (C) 2020 Nathan Dwarshuis\n"
},
{
"path": "dev/org-ml-test-external.el",
"chars": 243,
"preview": ";;; org-ml-test-external.el --- External tests for org-ml -*- lexical-binding: t; -*-\n\n;;; Commentary:\n\n;;; Code:\n\n(requ"
},
{
"path": "dev/org-ml-test-internal.el",
"chars": 105884,
"preview": ";;; org-ml-test-internal.el --- Internal tests for org-ml -*- lexical-binding: t; -*-\n\n;;; Commentary:\n\n;;; Code:\n\n(requ"
},
{
"path": "docs/api-reference.md",
"chars": 241576,
"preview": "# API Reference\n\n## String Conversion\n\n\nConvert nodes to strings.\n\n* [org-ml-to-string](#org-ml-to-string-node) `(node)`"
},
{
"path": "docs/cookbook.md",
"chars": 638,
"preview": "# org-ml cookbook\n\nThe following are a list of common use cases and formulationsfor `org-ml`. If a function is not avail"
},
{
"path": "env-28.2.yml",
"chars": 4031,
"preview": "name: org-ml-28.2\nchannels:\n - conda-forge\ndependencies:\n - _libgcc_mutex=0.1=conda_forge\n - _openmp_mutex=4.5=2_gnu\n"
},
{
"path": "env-29.3.yml",
"chars": 4094,
"preview": "name: org-ml-29.3\nchannels:\n - conda-forge\ndependencies:\n - _libgcc_mutex=0.1=conda_forge\n - _openmp_mutex=4.5=2_gnu\n"
},
{
"path": "env-30.1.yml",
"chars": 3893,
"preview": "name: org-ml-30.1\nchannels:\n - conda-forge\ndependencies:\n - _libgcc_mutex=0.1=conda_forge\n - _openmp_mutex=4.5=2_gnu\n"
},
{
"path": "init.el",
"chars": 1570,
"preview": "(defun fix-null-term (s)\n \"Fix string S with extra wonky null terminators.\n\nFor whatever reason this affects certain st"
},
{
"path": "org-ml-macs.el",
"chars": 21402,
"preview": ";;; org-ml-macs.el --- Macros for org-ml -*- lexical-binding: t; -*-\n\n;; Author: Nathan Dwarshuis <ndwar@yavin4.ch>\n\n;; "
},
{
"path": "org-ml.el",
"chars": 349714,
"preview": ";;; org-ml.el --- Functional Org Mode API -*- lexical-binding: t; -*-\n\n;; Copyright (C) 2020 Nathan Dwarshuis\n\n;; Autho"
}
]
About this extraction
This page contains the full source code of the ndwarshuis/om.el GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 25 files (1.0 MB), approximately 303.6k tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.