├── .github
└── workflows
│ └── lint.yml
├── .gitignore
├── .nomake
├── .keep
├── archive.lock
├── flake.lock
└── flake.nix
├── LICENSE
├── README.org
├── changelog.org
├── extras
├── README.md
├── counsel-org-starter.el
├── helm-org-starter.el
└── org-starter-extras.el
├── flake.lock
├── flake.nix
├── org-starter-swiper.el
├── org-starter.el
└── screenshots
└── org-starter-refile-by-key.png
/.github/workflows/lint.yml:
--------------------------------------------------------------------------------
1 | name: 'Lint and compile'
2 | on: { push: { paths: [ '**.el' ] } }
3 | jobs:
4 | lint:
5 | runs-on: ubuntu-latest
6 | strategy:
7 | matrix:
8 | emacs_version: ["snapshot"]
9 | steps:
10 | - uses: purcell/setup-emacs@master
11 | with:
12 | version: ${{ matrix.emacs_version }}
13 | - uses: actions/checkout@v2
14 | - name: Install dependencies
15 | run: |
16 | cat <(jq -r '.nodes.root.inputs | map(.) | .[]' .nomake/flake.lock) \
17 | <(jq -r 'keys | .[]' .nomake/archive.lock) \
18 | <(echo 'package-lint') \
19 | | xargs emacs -batch -l package --eval \
20 | "(progn
21 | (push '(\"melpa\" . \"https://melpa.org/packages/\")
22 | package-archives)
23 | (package-initialize)
24 | (when command-line-args-left
25 | (package-refresh-contents))
26 | (dolist (package-name command-line-args-left)
27 | (let ((package (intern package-name)))
28 | (when (and package
29 | (not (memq package
30 | '(org-starter org-starter-swiper))))
31 | (package-install (cadr (assq package
32 | package-archive-contents)))))))"
33 | - name: Run package-lint
34 | run: |
35 | for file in org-starter.el org-starter-swiper.el
36 | do
37 | emacs -l package --eval "(push '(\"melpa\" . \"https://melpa.org/packages/\") package-archives)" --eval "(package-initialize)" -L . -batch -l package-lint \
38 | -f package-lint-batch-and-exit $file
39 | done
40 |
41 | byte-compile:
42 | runs-on: ubuntu-latest
43 | strategy:
44 | matrix:
45 | emacs_version: ["25.1","25.2","25.3","26.1","26.2","26.3","27.1","27.2","snapshot"]
46 | steps:
47 | - uses: purcell/setup-emacs@master
48 | with:
49 | version: ${{ matrix.emacs_version }}
50 | - uses: actions/checkout@v2
51 | - name: Install dependencies
52 | run: |
53 | cat <(jq -r '.nodes.root.inputs | map(.) | .[]' .nomake/flake.lock) \
54 | <(jq -r 'keys | .[]' .nomake/archive.lock) \
55 | <(echo 'package-lint') \
56 | | xargs emacs -batch -l package --eval \
57 | "(progn
58 | (push '(\"melpa\" . \"https://melpa.org/packages/\")
59 | package-archives)
60 | (package-initialize)
61 | (when command-line-args-left
62 | (package-refresh-contents))
63 | (dolist (package-name command-line-args-left)
64 | (let ((package (intern package-name)))
65 | (when (and package
66 | (not (memq package
67 | '(org-starter org-starter-swiper))))
68 | (package-install (cadr (assq package
69 | package-archive-contents)))))))"
70 | - name: Byte-compile
71 | if: ${{ true }}
72 | run: |
73 | for file in org-starter.el org-starter-swiper.el
74 | do
75 | emacs -batch -l bytecomp -l package --eval "(push '(\"melpa\" . \"https://melpa.org/packages/\") package-archives)" --eval "(package-initialize)" -L . \
76 | --eval "(setq byte-compile-error-on-warn t)" \
77 | -f batch-byte-compile $file
78 | done
79 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.elc
2 | .pre-commit-config.yaml
3 | result
4 |
--------------------------------------------------------------------------------
/.nomake/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/akirak/org-starter/cd9c5c0402de941299d1c8901f26a8f24d755022/.nomake/.keep
--------------------------------------------------------------------------------
/.nomake/archive.lock:
--------------------------------------------------------------------------------
1 | {}
2 |
--------------------------------------------------------------------------------
/.nomake/flake.lock:
--------------------------------------------------------------------------------
1 | {
2 | "nodes": {
3 | "dash": {
4 | "flake": false,
5 | "locked": {
6 | "lastModified": 1632096711,
7 | "narHash": "sha256-oeIUEe5OGgij6IessN6bmS7re5r+D5BlrU4MOsaK3JE=",
8 | "owner": "magnars",
9 | "repo": "dash.el",
10 | "rev": "da167c51e9fd167a48d06c7c0ee8e3ac7abd9718",
11 | "type": "github"
12 | },
13 | "original": {
14 | "owner": "magnars",
15 | "repo": "dash.el",
16 | "type": "github"
17 | }
18 | },
19 | "ivy": {
20 | "flake": false,
21 | "locked": {
22 | "lastModified": 1640971806,
23 | "narHash": "sha256-4pnpTYwvMRE9Wv2MUNGoLgX+WD1QZnCLbT0aarBuOxY=",
24 | "owner": "abo-abo",
25 | "repo": "swiper",
26 | "rev": "c97ea72285f2428ed61b519269274d27f2b695f9",
27 | "type": "github"
28 | },
29 | "original": {
30 | "owner": "abo-abo",
31 | "repo": "swiper",
32 | "type": "github"
33 | }
34 | },
35 | "org-starter": {
36 | "flake": false,
37 | "locked": {
38 | "lastModified": 1640880380,
39 | "narHash": "sha256-5H+V2bIjTV50FNXtzU97O5A/jVAIObJTz3NKZt0iMH4=",
40 | "owner": "akirak",
41 | "repo": "org-starter",
42 | "rev": "6b1b3b045390bf1cff8214ece54da07c7a0aa8ad",
43 | "type": "github"
44 | },
45 | "original": {
46 | "owner": "akirak",
47 | "repo": "org-starter",
48 | "type": "github"
49 | }
50 | },
51 | "org-starter-swiper": {
52 | "flake": false,
53 | "locked": {
54 | "lastModified": 1640880380,
55 | "narHash": "sha256-5H+V2bIjTV50FNXtzU97O5A/jVAIObJTz3NKZt0iMH4=",
56 | "owner": "akirak",
57 | "repo": "org-starter",
58 | "rev": "6b1b3b045390bf1cff8214ece54da07c7a0aa8ad",
59 | "type": "github"
60 | },
61 | "original": {
62 | "owner": "akirak",
63 | "repo": "org-starter",
64 | "type": "github"
65 | }
66 | },
67 | "root": {
68 | "inputs": {
69 | "dash": "dash",
70 | "ivy": "ivy",
71 | "org-starter": "org-starter",
72 | "org-starter-swiper": "org-starter-swiper",
73 | "swiper": "swiper"
74 | }
75 | },
76 | "swiper": {
77 | "flake": false,
78 | "locked": {
79 | "lastModified": 1640971806,
80 | "narHash": "sha256-4pnpTYwvMRE9Wv2MUNGoLgX+WD1QZnCLbT0aarBuOxY=",
81 | "owner": "abo-abo",
82 | "repo": "swiper",
83 | "rev": "c97ea72285f2428ed61b519269274d27f2b695f9",
84 | "type": "github"
85 | },
86 | "original": {
87 | "owner": "abo-abo",
88 | "repo": "swiper",
89 | "type": "github"
90 | }
91 | }
92 | },
93 | "root": "root",
94 | "version": 7
95 | }
96 |
--------------------------------------------------------------------------------
/.nomake/flake.nix:
--------------------------------------------------------------------------------
1 | {
2 | description =
3 | "THIS IS AN AUTO-GENERATED FILE. PLEASE DON'T EDIT IT MANUALLY.";
4 | inputs = {
5 | dash = {
6 | flake = false;
7 | owner = "magnars";
8 | repo = "dash.el";
9 | type = "github";
10 | };
11 | ivy = {
12 | flake = false;
13 | owner = "abo-abo";
14 | repo = "swiper";
15 | type = "github";
16 | };
17 | org-starter = {
18 | flake = false;
19 | owner = "akirak";
20 | repo = "org-starter";
21 | type = "github";
22 | };
23 | org-starter-swiper = {
24 | flake = false;
25 | owner = "akirak";
26 | repo = "org-starter";
27 | type = "github";
28 | };
29 | swiper = {
30 | flake = false;
31 | owner = "abo-abo";
32 | repo = "swiper";
33 | type = "github";
34 | };
35 | };
36 | outputs = { ... }: { };
37 | }
38 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.org:
--------------------------------------------------------------------------------
1 | * org-starter
2 |
3 | #+BEGIN_HTML
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | #+END_HTML
12 |
13 | Org Starter is a framework for basic configuration of Emacs Org Mode. It
14 | allows you to configure Org Mode easily even with many files and
15 | directories.
16 |
17 | The standard way to configure Org Mode is set a bunch of variables such
18 | as =org-agenda-files= and =org-refile-targets=. This makes it hard to
19 | add/delete files to/from the configuration. Org Starter lets you
20 | configure Org Mode in a file-centric and incremental manner, which
21 | scales well especially if you have many Org files and sometimes have to
22 | tweak the file list.
23 |
24 | In other words, org-starter allows you to configure Org Mode in a manner
25 | similar to use-package. The following is an example file configuration
26 | with org-starter:
27 |
28 | #+BEGIN_SRC emacs-lisp
29 | (org-starter-define-file "subjects.org"
30 | :agenda t
31 | :refile '(:maxlevel . 9))
32 | #+END_SRC
33 | ** Table of contents
34 | :PROPERTIES:
35 | :TOC: siblings
36 | :END:
37 | - [[#prerequisites][Prerequisites]]
38 | - [[#installation][Installation]]
39 | - [[#configuration][Configuration]]
40 | - [[#load-path-for-org-files][Load path for org files]]
41 | - [[#external-configuration-files][External configuration files]]
42 | - [[#org-starter-swiper-config-files][org-starter-swiper-config-files]]
43 | - [[#extras][Extras]]
44 | - [[#loading-local-variables-in-org-files-without-confirmation][Loading local variables in Org files without confirmation]]
45 | - [[#usage][Usage]]
46 | - [[#configure-directories][Configure directories]]
47 | - [[#configure-files][Configure files]]
48 | - [[#quickly-access-a-particular-file-with-a-shortcut-key][Quickly access a particular file with a shortcut key]]
49 | - [[#org-starter-def-macro][org-starter-def macro]]
50 | - [[#configure-capture-templates][Configure capture templates]]
51 | - [[#extras][Extras]]
52 | - [[#locate-a-file][Locate a file]]
53 | - [[#load-all-known-files][Load all known files]]
54 | - [[#jump-to-a-file][Jump to a file]]
55 | - [[#jump-to-a-file-alternative-mode][Jump to a file (alternative mode)]]
56 | - [[#refile-an-entry-to-a-file][Refile an entry to a file]]
57 | - [[#helm-interface-to-visit-an-org-file][Helm interface to visit an Org file]]
58 | - [[#counsel-interface][Counsel interface]]
59 | - [[#related-packages][Related packages]]
60 | - [[#license][License]]
61 |
62 | ** Prerequisites
63 | - Emacs 25.1
64 | - =dash= and =dash-functional=
65 | - =swiper= if you use =org-starter-swiper=.
66 |
67 | ** Installation
68 | Install =org-starter= package from MELPA.
69 |
70 | If you use =org-starter-swiper=, install =org-starter-swiper= as well.
71 |
72 | Note: =counsel-org-starter= and =helm-org-starter= in this repository are not
73 | available on MELPA yet. Install them individually after installing
74 | =org-starter= if you need them.
75 | ** Configuration
76 | *** Load path for org files
77 | You can set up a "load path" for Org files. This path is later used to
78 | find an Org file with a specific file name. To set the load path,
79 | customize =org-starter-path=.
80 |
81 | You can also add directories to the load path by calling
82 | =org-starter-define-directory= with =:add-to-path= option.
83 | *** External configuration files
84 | An obvious way to configure Org files using org-starter is to put the configuration in your Emacs initialization file, i.e. =~/.emacs.d/init.el=. Org Starter also allows you to put it in an external configuration file residing in the same directory as your Org files. This is useful if have some host-local configuration and don't want to put it in your =init.el=. Org Starter is about Org files, so it makes sense to configure the package in alongside the files.
85 |
86 | To use this feature, set =org-starter-load-config-files= custom variable to t.
87 | Now you can put your configuration in =~/org/.org-config.el= if =~/org/= is included in =org-starter-path=:
88 |
89 | #+begin_src emacs-lisp
90 | ;; ~/.emacs.d/init.el: Configure org-starter
91 | (use-package org-starter
92 | :custom
93 | ;; Enable external configuration files loaded from org-starter-path
94 | (org-starter-load-config-files t))
95 |
96 | ;; Your custom-file: Set org-starter-path
97 | (custom-set-variables
98 | ...
99 | '(org-starter-path (quote ("~/org/")))
100 | ...
101 | )
102 |
103 | ;; Now you can put your configuration in ~/org/.org-config.el
104 | (org-starter-def "cpb.org")
105 | #+end_src
106 |
107 | You can put the configuration in any directories in =org-starter-path=. It is possible for you to put the configuration in a different directory
108 | **** org-starter-swiper-config-files
109 | =org-starter-swiper-config-files= command available from =org-starter-swiper=, which is a separate package, lets you run [[https://github.com/abo-abo/swiper][swiper]] through your configuration files. It is handy for finding a particular location in your configuration. It may be a good idea to bind a key to the command:
110 | *** Extras
111 | #+begin_src emacs-lisp
112 | (add-to-list 'org-starter-extra-alternative-find-file-map
113 | '(";" org-starter-swiper-config-files "config")
114 | t)
115 | #+end_src
116 |
117 | =org-starter-extra-alternative-find-file-map= is a list of commands available when you run =org-starter-alternative-find-file-by-key= command:
118 |
119 | #+begin_src emacs-lisp
120 | (define-key (kbd "C-c j") #'org-starter-alternative-find-file-by-key)
121 | #+end_src
122 |
123 | The following =org-capture= template lets you add a configuration quickly to one of your org-starter configuration files. =org-starter-find-config-file= lets you select an existing configuration file, and the entire target function navigates to the end of the selected file:
124 |
125 | #+begin_src emacs-lisp
126 | (org-starter-def-capture "e" "Personal Emacs configuration"
127 | plain (function (lambda ()
128 | (org-starter-find-config-file)
129 | (goto-char (point-max))))
130 | "%i"
131 | :unnarrowed t)
132 | #+end_src
133 | *** Loading local variables in Org files without confirmation
134 | You may have added local variables to your Org files.
135 | It is annoying to answer "yes" every time Emacs asks you if you are sure you want to load the variables. This can be skipped by enabling =org-starter-mode= and setting =org-starter-enable-local-variables= to =:all=. That is, =enable-local-variables= is temporarily overridden while a file registered by org-starter is loaded.
136 |
137 | Since variables defined in your own files are trusted, this is generally considered safe. However, when you set this option to =:all=, please don't add a file that can be edited by someone else to =org-starter-known-files=, as local variables defined by others can bring a security risk.
138 | ** Usage
139 | *** Configure directories
140 | Use =org-starter-define-directory= function to define a directory that
141 | contains Org files. You can add the directory to agenda files and/or
142 | refile targets via its options.
143 |
144 | You can also add it to the load path via =:add-to-path= option.
145 |
146 | For details of options, run =C-h f org-starter-define-directory=.
147 |
148 | *** Configure files
149 | Use =org-starter-define-file= function to define an Org file. As with
150 | directory definitions, you can add the file to agenda files and/or
151 | refile targets.
152 |
153 | You can also define Org files inside =org-starter-define-directory= form
154 | as =:files= option.
155 |
156 | For details, run =C-h f org-starter-define-file=.
157 |
158 | **** Quickly access a particular file with a shortcut key
159 | =org-starter-define-file= accepts optional =:key= property, whose value should be a key passed to =kbd= function. This property is used by =org-starter-find-file-by-key=, =org-starter-alternative-find-file-by-key=, and =org-starter-refile-by-key= commands, which enter a transient state to operate on a particular file quickly.
160 |
161 | [[file:screenshots/org-starter-refile-by-key.png]]
162 |
163 | You can also add custom commands to the transient keymaps by setting =org-starter-extra-find-file-map=, =org-starter-extra-alternative-find-file-map=, and =org-starter-extra-refile-map=, respectively.
164 |
165 | #+begin_src emacs-lisp
166 | (setq org-starter-extra-refile-map
167 | '(("/" org-refile "normal refile")))
168 | #+end_src
169 |
170 | For example, you can add a function that refiles entries into a date tree using my [[https://github.com/akirak/org-reverse-datetree][org-reverse-datetree]] package as in [[https://github.com/akirak/org-reverse-datetree#defining-a-refile-function][this example]].
171 | *** =org-starter-def= macro
172 | You can also use =org-starter-def= define either a file or a directory.
173 | Depending on the type of the argument, it calls either
174 | =org-starter-define-file= or =org-starter-define-directory=. It supports
175 | the same functionality as the two functions, but it allows you to define
176 | files and directories slightly more concisely.
177 |
178 | It basically supports the same as options as
179 | =org-starter-define-file=/=org-starter-define-directory=, but it doesn't
180 | need quoting. For example, the following two directives are equivalent:
181 |
182 | #+BEGIN_SRC emacs-lisp
183 | (org-starter-define-file "~/hello.org"
184 | :refile '(:maxlevel . 3))
185 |
186 | (org-starter-def "~/hello.org"
187 | :refile (:maxlevel . 3))
188 | #+END_SRC
189 |
190 | When you define a directory using =org-starter-def=, you can pass
191 | multiple arguments as =:files= option:
192 |
193 | #+BEGIN_SRC emacs-lisp
194 | (org-starter-def "~/my-directory"
195 | :files
196 | ("file1.org" :agenda t)
197 | ("file2.org" :agenda nil :required nil))
198 | #+END_SRC
199 |
200 | It also supports an additional option =:config=. Its argument is
201 | evaluated after the other options are applied, as in =use-package=. This
202 | is executed if and only if the file/directory exists. It can take
203 | multiple arguments:
204 |
205 | #+BEGIN_SRC emacs-lisp
206 | (org-starter-def "~/my-directory"
207 | :config
208 | (do-something)
209 | (do-another-thing))
210 | #+END_SRC
211 | *** Configure capture templates
212 | Org Starter provides two ways to incrementally define org-capture templates:
213 |
214 | - =:capture= property in =org-starter-define-file=, which lets you omit the file name of each template target. =(file FILENAME)= becomes =file= here.
215 | - =org-starter-def-capture= macro, which lets you omit the directory of a file name in template target. The file is searched from the load path. If there is no file existing in the load path, the template is not added.
216 |
217 | Templates added by org-starter are sorted alphabetically, so they are grouped by prefix letters even if they are defined in distributed locations.
218 |
219 | Each template entry added by these functions is transformed by a function specified as the value of =org-starter-capture-template-map-function= custom variable. This can be used to apply rules to your capture templates.
220 |
221 | There is also =org-starter-initial-capture-templates= custom variable, which is a recommended way to define template groups.
222 | *** Extras
223 | **** Locate a file
224 | You can use =org-starter-locate-file= function to find an Org file
225 | contained in one of the directories in =org-starter-path=:
226 |
227 | #+BEGIN_EXAMPLE
228 | (org-starter-locate-file "tasks.org")
229 | #+END_EXAMPLE
230 |
231 | To locate a file which is not in the path but already registered
232 | (defined) as a known file, use the function with an extra third
233 | argument. This function first tries to find a file in the list of known
234 | files:
235 |
236 | #+BEGIN_SRC emacs-lisp
237 | (org-starter-locate-file "file-not-in-path.org" nil t)
238 | #+END_SRC
239 |
240 | **** Load all known files
241 | It is sometimes convenient to load a specific set of Org files into
242 | Emacs as buffers. For example, you can search headings in the live Org
243 | buffers using =counsel-org-goto-all=.
244 |
245 | - To load all files registered by =org-starter-define-file= into Emacs,
246 | use =org-starter-load-all-known-files= command.
247 | - To load all files in =org-starter-path= into Emacs, use
248 | =org-starter-load-all-files-in-path= command.
249 | **** Jump to a file
250 | :PROPERTIES:
251 | :CREATED_TIME: [2019-06-22 Sat 09:29]
252 | :END:
253 | If you set =:key= of a file in =org-starter-define-file=, you can jump to the file quickly with =org-starter-find-file-by-key= command.
254 |
255 | You can also define extra bindings for the commands by adding entries to =org-starter-extra-find-file-map=:
256 |
257 | #+begin_src emacs-lisp
258 | ;; Add a binding to jump to your Emacs init file
259 | (setq org-starter-extra-find-map
260 | '(("e" (lambda () (interactive) (find-file "~/.emacs.d/init.el")) "init.el")))
261 | #+end_src
262 | **** Jump to a file (alternative mode)
263 | This package also provides =org-starter-alternative-find-file-by-key=, which provides an alternative mode for jumping to a file. Like =org-starter-define-file=, it displays options based on =:key= property of your files, but it uses a different function, which is configured as
264 | =org-starter-alternative-find-function=, for visiting a selected file. For example, you can use [[https://github.com/alphapapa/helm-org-rifle][helm-org-rifle-files]] for performing a search in the selected file:
265 |
266 | #+begin_src emacs-lisp
267 | (setq org-starter-alternative-find-function 'helm-org-rifle-files)
268 | #+end_src
269 | **** Refile an entry to a file
270 | When you are visiting a file in Org mode, you can use =org-starter-refile-by-key= to refile the current entry to a particular file. The refile level as set in =:refile= option is used for producing candidates.
271 |
272 | Like the previous commands, you can add extra bindings to the command through =org-starter-extra-refile-map=. If you use [[https://github.com/akirak/org-reverse-datetree][org-reverse-datetree]], it is a good idea to define a custom refile function for your datetree file and add it to the map. =org-starter-extras.el= in this repository provides a shortcut for defining such a function concisely:
273 |
274 | #+begin_src emacs-lisp
275 | ;; Define org-starter-refile-cpb-datetree function
276 | (org-starter-extras-def-reverse-datetree-refile "cpb.org"
277 | '("CREATED_TIME" "CLOSED"))
278 |
279 | (add-to-list 'org-starter-extra-refile-map
280 | '("p" org-starter-refile-cpb-datetree "cpb"))
281 | #+end_src
282 | *** COMMENT org-starter-utils library :no_export:
283 | :PROPERTIES:
284 | :TOC: ignore
285 | :END:
286 | # I have removed this file, so I will hide this subsection.
287 |
288 | =org-starter-utils.el= is a collection of utilities related to Org mode.
289 | It is part of =org-starter= package on MELPA and shipped with it, but it does not depend on =org-starter.el=,
290 | so you can use it without loading =org-starter.el=.
291 | Utilities in the library are designed to be useful with/without org-starter.
292 | **** Avy and Org
293 | The library provides some [[https://github.com/abo-abo/avy][avy]] interfaces to the features of Org mode.
294 | You need to install avy to use these functions.
295 |
296 | - =org-starter-utils-avy-id= is a function which returns =ID= property of an entry selected with avy.
297 | If the property is not set on the entry, it generates a new one.
298 | - Similarly, =org-starter-utils-avy-custom-id= is a function which returns =CUSTOM_ID= property of an entry selected with avy.
299 | If the property is not set on the entry, it generates a new one.
300 | - =org-starter-utils-avy-store-link-to-heading= stores a link to an entry selected with avy.
301 | ** Related packages
302 | You may find the following packages useful if you use org-starter:
303 |
304 | - [[https://github.com/akirak/ivy-omni-org][ivy-omni-org]]
305 | - [[https://github.com/akirak/org-reverse-datetree][org-reverse-datetree]]
306 | ** License
307 | GPL v3
308 | # Local Variables:
309 | # before-save-hook: org-make-toc
310 | # End:
311 |
--------------------------------------------------------------------------------
/changelog.org:
--------------------------------------------------------------------------------
1 | * Changelog
2 | ** org-starter 0.2.9 (2020-11-12)
3 | =org-starter-define-file= now accepts =:minor-modes= argument, which can be used to activate certain monor modes in only in specific files:
4 |
5 | #+begin_src emacs-lisp
6 | (org-starter-define-file "practice.org"
7 | :minor-modes
8 | '(org-recur-mode
9 | (org-bullets-mode 1)
10 | (org-edna-mode -1)))
11 | #+end_src
12 |
13 | In the example above, =org-recur-mode= and =org-bullets-mode= is turned on in =practice.org=, and =org-edna-mode= is turned off in the file.
14 | ** org-starter 0.2.8 (2020-03-21)
15 | =org-starter-def-capture= now accepts non-string files in targets.
16 |
17 | For example, the following definition caused an error in the previous versions, but it is considered valid if =my-org-file-symbol= refers to an existing Org file.
18 |
19 | #+begin_src emacs-lisp
20 | (org-starter-def-capture "x" "My capture template"
21 | entry
22 | (file my-org-file-symbol)
23 | "* %?")
24 | #+end_src
25 |
--------------------------------------------------------------------------------
/extras/README.md:
--------------------------------------------------------------------------------
1 | Files in this directory are no longer maintained.
2 |
--------------------------------------------------------------------------------
/extras/counsel-org-starter.el:
--------------------------------------------------------------------------------
1 | ;;; counsel-org-starter.el --- Counsel interface to org-starter -*- lexical-binding: t -*-
2 |
3 | ;; Copyright (C) 2018 Akira Komamura
4 |
5 | ;; Author: Akira Komamura
6 | ;; Version: 1.0-pre
7 | ;; Package-Requires: ((emacs "25.1") (ivy "0.10") (memoize "1.1") (org-starter "0.1"))
8 | ;; URL: https://github.com/akirak/org-starter
9 |
10 | ;; This file is not part of GNU Emacs.
11 |
12 | ;;; License:
13 |
14 | ;; This program is free software: you can redistribute it and/or modify
15 | ;; it under the terms of the GNU General Public License as published by
16 | ;; the Free Software Foundation, either version 3 of the License, or
17 | ;; (at your option) any later version.
18 | ;;
19 | ;; This program is distributed in the hope that it will be useful,
20 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 | ;; GNU General Public License for more details.
23 | ;;
24 | ;; You should have received a copy of the GNU General Public License
25 | ;; along with this program. If not, see .
26 |
27 | ;;; Commentary:
28 |
29 | ;; This is a Counsel/Ivy interface to org-starter.
30 |
31 | ;;; Code:
32 |
33 | (require 'ivy)
34 | (require 'org-starter)
35 | (require 'cl-lib)
36 | (require 'seq)
37 | (require 'memoize)
38 |
39 | (defcustom counsel-org-starter-goto-beginning nil
40 | "If non-nil, jump to the beginning of the file."
41 | :type 'boolean
42 | :group 'org-starter)
43 |
44 | (defun counsel-org-starter--get-buffer (filename)
45 | "Get a buffer visiting a known file named FILENAME (with/without its directory)."
46 | (let* ((fpath (org-starter-locate-file filename nil t))
47 | (buf (or (find-buffer-visiting fpath)
48 | (find-file-noselect fpath))))
49 | (when counsel-org-starter-goto-beginning
50 | (with-current-buffer buf
51 | (goto-char (point-min))))
52 | buf))
53 |
54 | (defun counsel-org-starter--file-list (&optional deprecated agenda-files)
55 | "Return a list of known Org files.
56 |
57 | By default, this function returns a list of files in `org-starter-known-file',
58 | excluding deprecated files. Each file name in the result does not contain its
59 | directory.
60 |
61 | If DEPRECATED is non-nil, the result includes deprecated files.
62 |
63 | If AGENDA-FILES is non-nil, files in `org-agenda-files` are appended to the
64 | result."
65 | (let ((files (cl-copy-list org-starter-known-files))
66 | filenames)
67 | (unless deprecated
68 | (cl-delete-if (lambda (fpath) (member fpath org-starter-deprecated-files))
69 | files))
70 | (setq filenames (mapcar #'file-name-nondirectory files))
71 | (if agenda-files
72 | (append filenames
73 | (mapcar #'abbreviate-file-name
74 | (seq-difference (org-agenda-files) files #'file-equal-p)))
75 | filenames)))
76 |
77 | (memoize 'counsel-org-starter--file-list)
78 |
79 | (defun counsel-org-starter-known-file (&optional arg)
80 | "Choose a known file.
81 |
82 | If prefix ARG is given, deprecated files are included in the candidates."
83 | (interactive "P")
84 | (ivy-read "org-starter known file: "
85 | (counsel-org-starter--file-list arg)
86 | :caller 'counsel-org-starter-known-file
87 | :action (lambda (cand)
88 | (switch-to-buffer (counsel-org-starter--get-buffer cand)))))
89 |
90 | (defun counsel-org-starter (&optional arg)
91 | "Choose a known file or a file in `org-agenda-files'.
92 |
93 | If prefix ARG is given, deprecated files are included in the candidates."
94 | (interactive "P")
95 | (ivy-read "org-starter: "
96 | (counsel-org-starter--file-list arg t)
97 | :caller 'counsel-org-starter-known-file
98 | :action (lambda (cand)
99 | (switch-to-buffer (counsel-org-starter--get-buffer cand)))))
100 |
101 | (ivy-add-actions
102 | #'counsel-org-starter-known-file
103 | '(("j" (lambda (cand)
104 | (switch-to-buffer-other-window (counsel-org-starter--get-buffer cand)))
105 | "other window")))
106 |
107 | (provide 'counsel-org-starter)
108 | ;;; counsel-org-starter.el ends here
109 |
--------------------------------------------------------------------------------
/extras/helm-org-starter.el:
--------------------------------------------------------------------------------
1 | ;;; helm-org-starter.el --- Helm interface for org-starter.el -*- lexical-binding: t -*-
2 |
3 | ;; Copyright (C) 2018 by Akira Komamura
4 |
5 | ;; Author: Akira Komamura
6 | ;; Version: 0.1.0
7 | ;; Package-Requires: ((emacs "25.1") (helm "1.9.4") (org-starter "0.1") (s "1.12"))
8 | ;; URL: https://github.com/akirak/org-starter
9 |
10 | ;; This file is not part of GNU Emacs.
11 |
12 | ;;; License:
13 |
14 | ;; This program is free software: you can redistribute it and/or modify
15 | ;; it under the terms of the GNU General Public License as published by
16 | ;; the Free Software Foundation, either version 3 of the License, or
17 | ;; (at your option) any later version.
18 | ;;
19 | ;; This program is distributed in the hope that it will be useful,
20 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 | ;; GNU General Public License for more details.
23 | ;;
24 | ;; You should have received a copy of the GNU General Public License
25 | ;; along with this program. If not, see .
26 |
27 | ;;; Commentary:
28 |
29 | ;; This is a Helm interface to Org buffers.
30 |
31 | ;;; Code:
32 |
33 | (require 'org-starter)
34 | (require 'seq)
35 | (require 'helm)
36 | (require 'cl-lib)
37 | (require 's)
38 |
39 | (defclass helm-org-starter-known-file-source-class (helm-source-sync)
40 | ((candidates :initform
41 | (lambda ()
42 | (cl-loop for fpath in org-starter-known-files
43 | collect (cons (helm-org-starter--format-file-candidate fpath)
44 | fpath))))))
45 |
46 | (defcustom helm-org-starter-file-actions
47 | '(("Find file" . find-file))
48 | "Customizable action list for helm-org-starter.
49 |
50 | The function in each item takes a file name as the argument."
51 | :group 'helm-org-starter
52 | :type '(alist :key-type string :value-type function))
53 |
54 | (defcustom helm-org-starter-buffer-sort-method nil
55 | "How to sort buffer entries in each Helm source."
56 | :group 'helm-org-starter
57 | :type '(choice (const :tag "Not sorted" nil)
58 | (const :tag "By file path" filepath)))
59 |
60 | (defun helm-org-starter--get-file-info (&optional buffer)
61 | "Get information on the Org BUFFER.
62 |
63 | The result is an alist."
64 | (with-current-buffer (or buffer (current-buffer))
65 | (org-with-wide-buffer
66 | `((title . ,(progn (goto-char (point-min))
67 | (when (re-search-forward
68 | "^\\#\\+[Tt][Ii][Tt][Ll][Ee]: \\(.+\\)$"
69 | nil t)
70 | (match-string-no-properties 1))))
71 | (subtitle . ,(progn (goto-char (point-min))
72 | (when (re-search-forward
73 | "^\\#\\+[Ss][Uu][Bb][Tt][Ii][Tt][Ll][Ee]: \\(.+\\)$"
74 | nil t)
75 | (match-string-no-properties 1))))
76 | (filetags . ,(progn (goto-char (point-min))
77 | (when (re-search-forward
78 | "^\\#\\+[Ff][Ii][Ll][Ee][Tt][Aa][Gg][Ss]: \\(.+\\)$"
79 | nil t)
80 | (match-string-no-properties 1))))))))
81 |
82 | (defcustom helm-org-starter-column-width 40
83 | "The width of the first column."
84 | :group 'helm-org-starter
85 | :type 'integer)
86 |
87 | (defun helm-org-starter--format-buffer-candidate (buf)
88 | "Generate a Helm candidate title from BUF."
89 | (let* ((fpath (buffer-file-name buf))
90 | (title (concat (if fpath
91 | (concat (abbreviate-file-name (file-name-directory fpath))
92 | (propertize (file-name-nondirectory fpath) 'face 'helm-buffer-file))
93 | (buffer-name buf))
94 | (if (buffer-modified-p buf) " *" ""))))
95 | (let-alist (helm-org-starter--get-file-info buf)
96 | (concat (s-pad-right helm-org-starter-column-width " " title)
97 | " : "
98 | (cond
99 | ((and \.title \.subtitle)
100 | (concat (propertize \.title 'face 'org-document-title)
101 | " --- " \.subtitle))
102 | (\.title (propertize \.title 'face 'org-document-title))
103 | (t ""))
104 | (if \.filetags (propertize \.filetags 'face 'org-tag) "")))))
105 |
106 | (defun helm-org-starter--group-buffers ()
107 | "Group live Org buffers."
108 | (let ((agenda-files (mapcar #'expand-file-name (org-agenda-files))))
109 | (seq-group-by (lambda (buf)
110 | (let ((fpath (buffer-file-name buf)))
111 | (cond
112 | ((null fpath) 'nonfile)
113 | ((cl-member fpath org-starter-deprecated-files :test #'file-equal-p)
114 | 'deprecated)
115 | ((cl-member fpath agenda-files :test #'file-equal-p)
116 | 'agenda)
117 | ((cl-member fpath org-starter-known-files :test #'file-equal-p)
118 | 'known)
119 | (t 'other))))
120 | (cl-remove-if-not (lambda (buf)
121 | (with-current-buffer buf
122 | (eq major-mode 'org-mode)))
123 | (buffer-list)))))
124 |
125 | (defvar helm-org-starter-buffer-actions
126 | '(("Switch to buffer" . switch-to-buffer)
127 | ("Switch to buffer (other-window)" . switch-to-buffer)
128 | ("Kill buffer" . (lambda (x) (mapc #'kill-buffer (helm-marked-candidates))))))
129 |
130 | (defun helm-org-starter--sort-buffers (buffers method)
131 | "Sort a list of BUFFERS with METHOD.
132 |
133 | METHOD is a symbol that is supported by `helm-org-starter-buffer-sort-method'."
134 | (cl-case method
135 | (filepath (cl-sort buffers #'string< :key #'buffer-file-name))
136 | (otherwise buffers)))
137 |
138 | (defun helm-org-starter--make-source-from-buffers (name buffers)
139 | "Create a Helm source named NAME with BUFFERS as its candidates."
140 | (declare (indent 1))
141 | (helm-build-sync-source name
142 | :action 'helm-org-starter-buffer-actions
143 | :candidates (mapcar (lambda (buf)
144 | (cons (helm-org-starter--format-buffer-candidate buf)
145 | buf))
146 | (helm-org-starter--sort-buffers
147 | buffers
148 | helm-org-starter-buffer-sort-method))))
149 |
150 | (defun helm-org-starter--sources-from-buffer ()
151 | "Build a list of Helm sources for Org buffers."
152 | (let ((groups (helm-org-starter--group-buffers))
153 | (captions '(("Org agenda files" . agenda)
154 | ("Known files" . known)
155 | ("Deprecated" . deprecated)
156 | ("Other file buffers" . other)
157 | ("Non-file buffers" .nonfile))))
158 | (cl-loop for (name . symbol) in captions
159 | collect (helm-org-starter--make-source-from-buffers name
160 | (alist-get symbol groups)))))
161 |
162 | (defun helm-org-starter--format-file-candidate (filename)
163 | "Format a helm candidate title for FILENAME."
164 | (if-let ((buf (find-buffer-visiting filename)))
165 | (helm-org-starter--format-buffer-candidate buf)
166 | (abbreviate-file-name filename)))
167 |
168 | (defvar helm-org-starter-known-file-source
169 | (helm-make-source "org-starter known files"
170 | 'helm-org-starter-known-file-source-class
171 | :action 'helm-org-starter-file-actions))
172 |
173 | ;;;###autoload
174 | (defun helm-org-starter-known-files ()
175 | "Helm for `org-starter-known-files'."
176 | (interactive)
177 | (helm :sources 'helm-org-starter-known-file-source))
178 |
179 | (defun helm-org-starter-create-file-in-known-directory (filename)
180 | "Create FILENAME in a known directory via a Helm interface."
181 | (let ((action (lambda (dpath) (find-file (expand-file-name filename dpath)))))
182 | (helm :prompt (format "Choose a directory to save %s: " filename)
183 | :sources
184 | (list (helm-build-sync-source "Directories in the path"
185 | :candidates 'org-starter-path
186 | :action action)
187 | (helm-build-sync-source "Other known directories"
188 | :candidates (seq-difference org-starter-known-directories
189 | org-starter-path)
190 | :action action)))))
191 |
192 | (defvar helm-org-starter-dummy-file-source
193 | (helm-build-dummy-source "New file in a known directory"
194 | :action 'helm-org-starter-create-file-in-known-directory))
195 |
196 | ;;;###autoload
197 | (defun helm-org-starter (&optional arg)
198 | "Helm for a bunch of Org files and buffers.
199 |
200 | If prefix ARG is given, load all Org files in `org-starter-path'.
201 | Otherwise, all known files are loaded."
202 | (interactive "P")
203 | (if arg
204 | (org-starter-load-all-files-in-path)
205 | (org-starter-load-all-known-files))
206 | (helm :prompt "Org buffers: "
207 | :buffer "*helm-org-starter*"
208 | :sources (append (helm-org-starter--sources-from-buffer)
209 | (list 'helm-org-starter-dummy-file-source))))
210 |
211 | (provide 'helm-org-starter)
212 | ;;; helm-org-starter.el ends here
213 |
--------------------------------------------------------------------------------
/extras/org-starter-extras.el:
--------------------------------------------------------------------------------
1 | ;;; org-starter-extras.el --- Utilities that require extra dependencies -*- lexical-binding: t -*-
2 |
3 | ;; Copyright (C) 2019 Akira Komamura
4 |
5 | ;; Author: Akira Komamura
6 | ;; Version: 0.1
7 | ;; Package-Requires: ((emacs "25.1") (org-starter "0.2"))
8 | ;; URL: https://github.com/akirak/org-starter
9 |
10 | ;; This file is not part of GNU Emacs.
11 |
12 | ;;; License:
13 |
14 | ;; This program is free software: you can redistribute it and/or modify
15 | ;; it under the terms of the GNU General Public License as published by
16 | ;; the Free Software Foundation, either version 3 of the License, or
17 | ;; (at your option) any later version.
18 | ;;
19 | ;; This program is distributed in the hope that it will be useful,
20 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 | ;; GNU General Public License for more details.
23 | ;;
24 | ;; You should have received a copy of the GNU General Public License
25 | ;; along with this program. If not, see .
26 |
27 | ;;; Commentary:
28 |
29 | ;; This library provides a bunch of utilities for org-starter that
30 | ;; depend on extra packages (e.g. org-reverse-datetree) other than
31 | ;; org-starter itself.
32 |
33 | ;;; Code:
34 |
35 | (require 'cl-lib)
36 | (require 'org-starter)
37 |
38 | (declare-function 'org-reverse-datetree-refile-to-file "org-reverse-datetree")
39 |
40 | ;;;###autoload
41 | (cl-defmacro org-starter-extras-def-reverse-datetree-refile
42 | (filename date-properties &key ask-always)
43 | "Define a refile function to a reverse datetree.
44 |
45 | FILENAME is the name of the file which usually doesn't contain a
46 | directory. See `org-starter-define-file'.
47 |
48 | DATE-PROPERTIES is a list of property names to be used as the
49 | target date.
50 |
51 | If ASK-ALWAYS is non-nil, it is used as the value of the same
52 | property of `org-reverse-datetree-refile-to-file'.
53 | If it is nil, it is determined by the prefix argument."
54 | (declare (indent 1))
55 | (let ((function-name (intern (format "org-starter-refile-%s-datetree"
56 | (file-name-sans-extension filename)))))
57 | `(defun ,function-name (arg)
58 | (interactive "P")
59 | (require 'org-reverse-datetree)
60 | (org-reverse-datetree-refile-to-file
61 | (org-starter-locate-file ,filename nil t) nil
62 | :ask-always (or ,ask-always arg)
63 | :prefer ,(cl-typecase date-properties
64 | (symbol (symbol-value date-properties))
65 | (t date-properties))))))
66 |
67 | (provide 'org-starter-extras)
68 | ;;; org-starter-extras.el ends here
69 |
--------------------------------------------------------------------------------
/flake.lock:
--------------------------------------------------------------------------------
1 | {
2 | "nodes": {
3 | "elisp-helpers": {
4 | "flake": false,
5 | "locked": {
6 | "lastModified": 1644084222,
7 | "narHash": "sha256-Z7K0UkMvjZ+rwzhE2smK5GCl4LkrmY97MKkpay23yDo=",
8 | "owner": "emacs-twist",
9 | "repo": "elisp-helpers",
10 | "rev": "7e295072ec385d0ef7e46efca259d9276542cd6f",
11 | "type": "github"
12 | },
13 | "original": {
14 | "owner": "emacs-twist",
15 | "repo": "elisp-helpers",
16 | "type": "github"
17 | }
18 | },
19 | "elsa": {
20 | "flake": false,
21 | "locked": {
22 | "lastModified": 1644279463,
23 | "narHash": "sha256-uYx5LBvxv3F7OKWdBGiXrrWHSRt6/54hnE/tuxUTyqs=",
24 | "owner": "emacs-elsa",
25 | "repo": "Elsa",
26 | "rev": "82ffb6eecefde7e99383e4a657f17fe414287846",
27 | "type": "github"
28 | },
29 | "original": {
30 | "owner": "emacs-elsa",
31 | "repo": "Elsa",
32 | "type": "github"
33 | }
34 | },
35 | "emacs-ci": {
36 | "flake": false,
37 | "locked": {
38 | "lastModified": 1637854310,
39 | "narHash": "sha256-oYwxv+rb5fkxraAle2OMTO6dfIh7yvT3XwXK8IFYUvM=",
40 | "owner": "purcell",
41 | "repo": "nix-emacs-ci",
42 | "rev": "6ac997af7076d654521870c3a3caabdcc5c37399",
43 | "type": "github"
44 | },
45 | "original": {
46 | "owner": "purcell",
47 | "repo": "nix-emacs-ci",
48 | "type": "github"
49 | }
50 | },
51 | "flake-utils": {
52 | "locked": {
53 | "lastModified": 1644229661,
54 | "narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=",
55 | "owner": "numtide",
56 | "repo": "flake-utils",
57 | "rev": "3cecb5b042f7f209c56ffd8371b2711a290ec797",
58 | "type": "github"
59 | },
60 | "original": {
61 | "owner": "numtide",
62 | "repo": "flake-utils",
63 | "type": "github"
64 | }
65 | },
66 | "fromElisp": {
67 | "flake": false,
68 | "locked": {
69 | "lastModified": 1620725665,
70 | "narHash": "sha256-xLQDuSXjlTJUPftbT/PTegrn6yySoEYrFlUP5e8Kfuc=",
71 | "owner": "talyz",
72 | "repo": "fromElisp",
73 | "rev": "1c0d9b629b505a6d7ba050172b2fcaf43fa32801",
74 | "type": "github"
75 | },
76 | "original": {
77 | "owner": "talyz",
78 | "repo": "fromElisp",
79 | "type": "github"
80 | }
81 | },
82 | "gitignore": {
83 | "inputs": {
84 | "nixpkgs": [
85 | "nomake",
86 | "nixpkgs"
87 | ]
88 | },
89 | "locked": {
90 | "lastModified": 1635165013,
91 | "narHash": "sha256-o/BdVjNwcB6jOmzZjOH703BesSkkS5O7ej3xhyO8hAY=",
92 | "owner": "hercules-ci",
93 | "repo": "gitignore.nix",
94 | "rev": "5b9e0ff9d3b551234b4f3eb3983744fa354b17f1",
95 | "type": "github"
96 | },
97 | "original": {
98 | "owner": "hercules-ci",
99 | "repo": "gitignore.nix",
100 | "type": "github"
101 | }
102 | },
103 | "gnu-elpa": {
104 | "flake": false,
105 | "locked": {
106 | "lastModified": 1644874071,
107 | "narHash": "sha256-HbnydMb+TGjpTb8BddVhSz66yAEUaHJlGsPqA2SGV9E=",
108 | "ref": "main",
109 | "rev": "03415c72444609e4508ebf3fe264cba9c2eb4300",
110 | "revCount": 337,
111 | "type": "git",
112 | "url": "https://git.savannah.gnu.org/git/emacs/elpa.git"
113 | },
114 | "original": {
115 | "ref": "main",
116 | "type": "git",
117 | "url": "https://git.savannah.gnu.org/git/emacs/elpa.git"
118 | }
119 | },
120 | "melpa": {
121 | "flake": false,
122 | "locked": {
123 | "lastModified": 1644922769,
124 | "narHash": "sha256-oyVwe28cb+WN/KQdw5zTK+PmYGxYQXGoLlB/7d5NQVA=",
125 | "owner": "melpa",
126 | "repo": "melpa",
127 | "rev": "792361797f8895fb41791f02b4c27e9d41b55ffb",
128 | "type": "github"
129 | },
130 | "original": {
131 | "owner": "melpa",
132 | "repo": "melpa",
133 | "type": "github"
134 | }
135 | },
136 | "nixpkgs": {
137 | "locked": {
138 | "lastModified": 1643087856,
139 | "narHash": "sha256-EreC7gP/T566PDRZjqNoTvByTyvABEpJpWFtyNUDS0Y=",
140 | "path": "/nix/store/q5ipbyw3kxa7q9fia4c564rbdnhy4xsa-source",
141 | "rev": "8bd55a6a5ab05942af769c2aa2494044bff7f625",
142 | "type": "path"
143 | },
144 | "original": {
145 | "id": "nixpkgs",
146 | "type": "indirect"
147 | }
148 | },
149 | "nomake": {
150 | "inputs": {
151 | "elsa": "elsa",
152 | "emacs-ci": "emacs-ci",
153 | "flake-utils": "flake-utils",
154 | "gitignore": "gitignore",
155 | "gnu-elpa": [
156 | "gnu-elpa"
157 | ],
158 | "melpa": [
159 | "melpa"
160 | ],
161 | "nixpkgs": "nixpkgs",
162 | "package-lint": "package-lint",
163 | "twist": "twist"
164 | },
165 | "locked": {
166 | "lastModified": 1645156482,
167 | "narHash": "sha256-fE86Zn4yT9Rakkh2MMCJ0lkJys/D3BoVMEhI4J2+wNg=",
168 | "owner": "emacs-twist",
169 | "repo": "nomake",
170 | "rev": "e86fda919ea7a74d3be441b7521ba52be27145af",
171 | "type": "github"
172 | },
173 | "original": {
174 | "owner": "emacs-twist",
175 | "repo": "nomake",
176 | "type": "github"
177 | }
178 | },
179 | "package-lint": {
180 | "flake": false,
181 | "locked": {
182 | "lastModified": 1644654625,
183 | "narHash": "sha256-YprQ7XwzqHsBVEroNC4OXBzkjwX/y1T37Pw2M8kNVRQ=",
184 | "owner": "purcell",
185 | "repo": "package-lint",
186 | "rev": "fc30a795000a1ae98bb3d09e5b2929bedfc402fe",
187 | "type": "github"
188 | },
189 | "original": {
190 | "owner": "purcell",
191 | "repo": "package-lint",
192 | "type": "github"
193 | }
194 | },
195 | "root": {
196 | "inputs": {
197 | "gnu-elpa": "gnu-elpa",
198 | "melpa": "melpa",
199 | "nomake": "nomake"
200 | }
201 | },
202 | "twist": {
203 | "inputs": {
204 | "elisp-helpers": "elisp-helpers",
205 | "fromElisp": "fromElisp"
206 | },
207 | "locked": {
208 | "lastModified": 1644794204,
209 | "narHash": "sha256-NxXKZ8eIrVR2UmWyVAMKsOAIYiboe/WXWgHTMEUkCq4=",
210 | "owner": "emacs-twist",
211 | "repo": "twist.nix",
212 | "rev": "699b298a0e7aee862242d07d4c9b694136db66a5",
213 | "type": "github"
214 | },
215 | "original": {
216 | "owner": "emacs-twist",
217 | "repo": "twist.nix",
218 | "type": "github"
219 | }
220 | }
221 | },
222 | "root": "root",
223 | "version": 7
224 | }
225 |
--------------------------------------------------------------------------------
/flake.nix:
--------------------------------------------------------------------------------
1 | {
2 | description = "";
3 |
4 | inputs = {
5 | gnu-elpa = {
6 | url = "git+https://git.savannah.gnu.org/git/emacs/elpa.git?ref=main";
7 | flake = false;
8 | };
9 | melpa = {
10 | url = "github:melpa/melpa";
11 | flake = false;
12 | };
13 |
14 | nomake = {
15 | url = "github:emacs-twist/nomake";
16 | inputs.gnu-elpa.follows = "gnu-elpa";
17 | inputs.melpa.follows = "melpa";
18 | };
19 | };
20 |
21 | outputs =
22 | { self
23 | , nomake
24 | , ...
25 | } @ inputs:
26 | nomake.lib.mkFlake {
27 | src = ./.;
28 | localPackages = [
29 | "org-starter"
30 | "org-starter-swiper"
31 | ];
32 |
33 | github.lint.compile = true;
34 | };
35 | }
36 |
--------------------------------------------------------------------------------
/org-starter-swiper.el:
--------------------------------------------------------------------------------
1 | ;;; org-starter-swiper.el --- Swiper for org-starter -*- lexical-binding: t -*-
2 |
3 | ;; Copyright (C) 2019 Akira Komamura
4 |
5 | ;; Author: Akira Komamura
6 | ;; Version: 0.1.1
7 | ;; Package-Requires: ((emacs "25.1") (swiper "0.11") (org-starter "0.2.4"))
8 | ;; URL: https://github.com/akirak/org-starter
9 |
10 | ;; This file is not part of GNU Emacs.
11 |
12 | ;;; License:
13 |
14 | ;; This program is free software: you can redistribute it and/or modify
15 | ;; it under the terms of the GNU General Public License as published by
16 | ;; the Free Software Foundation, either version 3 of the License, or
17 | ;; (at your option) any later version.
18 | ;;
19 | ;; This program is distributed in the hope that it will be useful,
20 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 | ;; GNU General Public License for more details.
23 | ;;
24 | ;; You should have received a copy of the GNU General Public License
25 | ;; along with this program. If not, see .
26 |
27 | ;;; Commentary:
28 |
29 | ;; This library provides swiper integration for org-starter.
30 | ;; At present, only `org-starter-swiper-config-files' is provided.
31 |
32 | ;;; Code:
33 |
34 | (require 'org-starter)
35 | (require 'swiper)
36 | (require 'ivy)
37 |
38 | (defgroup org-starter-swiper nil
39 | "Swiper integration for org-starter."
40 | :group 'org-starter
41 | :group 'swiper)
42 |
43 | (defcustom org-starter-swiper-max-window-width 120
44 | "Maximum width of the window of `org-starter-swiper-config-files'.
45 |
46 | When this variable is set, `swiper-window-width' of the command
47 | cannot be greater than the value."
48 | :type 'number
49 | :group 'org-starter-swiper)
50 |
51 | (defcustom org-starter-swiper-width-function
52 | 'org-starter-swiper-default-width
53 | "Function to determine the width of the swiper contents."
54 | :type 'function
55 | :group 'org-starter-swiper)
56 |
57 | (defun org-starter-swiper-default-width ()
58 | "Calculate the inner width of the frame."
59 | (- (- (frame-width) (if (display-graphic-p) 0 1)) 4))
60 |
61 | ;;;###autoload
62 | (defun org-starter-swiper-config-files ()
63 | "Run `swiper-multi' for the config files."
64 | (interactive)
65 | (let* ((buffers (mapcar (lambda (file)
66 | (or (find-buffer-visiting file)
67 | (find-file-noselect file)))
68 | (org-starter--get-existing-config-files)))
69 | (default-width (funcall org-starter-swiper-width-function))
70 | (max-width org-starter-swiper-max-window-width)
71 | (swiper-window-width (if max-width
72 | (min max-width default-width)
73 | default-width)))
74 | (ivy-read "Swiper: " (swiper--multi-candidates buffers)
75 | :action #'swiper-multi-action-2
76 | ;; :update-fn #'org-starter-swiper--update-fn
77 | :unwind #'swiper--cleanup
78 | :caller 'org-starter-swiper-config-files)))
79 |
80 | (add-to-list 'ivy-format-functions-alist
81 | '(org-starter-swiper-config-files . swiper--all-format-function))
82 |
83 | (defun org-starter-swiper--config-file-other-window (x)
84 | "Move to candidate X."
85 | (when (> (length x) 0)
86 | (let ((buffer-name (get-text-property 0 'buffer x)))
87 | (when buffer-name
88 | (switch-to-buffer-other-window buffer-name)
89 | (goto-char (point-min))
90 | (forward-line (1- (read (get-text-property 0 'swiper-line-number x))))
91 | (re-search-forward
92 | (ivy--regex ivy-text)
93 | (line-end-position) t)))))
94 |
95 | (ivy-add-actions 'org-starter-swiper-config-files
96 | '(("j" org-starter-swiper--config-file-other-window "other window")))
97 |
98 | (defun org-starter-swiper--update-fn ()
99 | "Function run when input is updated in `org-starter-swiper-config-files'."
100 | (when-let ((current (ivy-state-current ivy-last))
101 | (buffer-name (get-text-property 0 'buffer current)))
102 | (with-ivy-window
103 | (swiper--cleanup)
104 | (switch-to-buffer buffer-name)
105 | (goto-char (point-min))
106 | (forward-line (1- (read (get-text-property 0 'swiper-line-number current))))
107 | (re-search-forward
108 | (ivy--regex ivy-text)
109 | (line-end-position) t)
110 | (isearch-range-invisible (line-beginning-position)
111 | (line-end-position))
112 | (swiper--add-overlays
113 | (ivy--regex ivy-text)))))
114 |
115 | (provide 'org-starter-swiper)
116 | ;;; org-starter-swiper.el ends here
117 |
--------------------------------------------------------------------------------
/org-starter.el:
--------------------------------------------------------------------------------
1 | ;;; org-starter.el --- A basic configuration framework for org mode -*- lexical-binding: t -*-
2 |
3 | ;; Copyright (C) 2018-2022 by Akira Komamura
4 |
5 | ;; Author: Akira Komamura
6 | ;; Version: 0.2.10
7 | ;; Package-Requires: ((emacs "25.1") (dash "2.18"))
8 | ;; URL: https://github.com/akirak/org-starter
9 |
10 | ;; This file is not part of GNU Emacs.
11 |
12 | ;;; License:
13 |
14 | ;; This program is free software: you can redistribute it and/or modify
15 | ;; it under the terms of the GNU General Public License as published by
16 | ;; the Free Software Foundation, either version 3 of the License, or
17 | ;; (at your option) any later version.
18 | ;;
19 | ;; This program is distributed in the hope that it will be useful,
20 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 | ;; GNU General Public License for more details.
23 | ;;
24 | ;; You should have received a copy of the GNU General Public License
25 | ;; along with this program. If not, see .
26 |
27 | ;;; Commentary:
28 |
29 | ;; This package helps you configure org mode. See README for details.
30 |
31 | ;;; Code:
32 |
33 | (require 'org)
34 | (require 'cl-lib)
35 | (require 'subr-x)
36 | (require 'dash)
37 | (require 'org-capture)
38 |
39 | (declare-function posframe-show "ext:posframe")
40 | (declare-function posframe-delete-frame "ext:posframe")
41 | (declare-function posframe-poshandler-frame-center "ext:posframe")
42 | (declare-function posframe-workable-p "ext:posframe")
43 | (defvar org-agenda-custom-commands)
44 | (defvar org-agenda-window-setup)
45 | (defvar org-agenda-sticky)
46 | (defvar org-agenda-buffer-name)
47 |
48 | ;;;; Compatibility
49 |
50 | (eval-and-compile
51 | (with-no-warnings
52 | (defalias 'org-starter--when-let* #'when-let)
53 | (function-put #'org-starter--when-let* 'lisp-indent-function 1)))
54 |
55 | (defconst org-starter-message-buffer "*org-starter message*")
56 |
57 | ;;;; Custom variables
58 | (defcustom org-starter-capture-template-map-function nil
59 | "A function used to transform each entry in `org-capture' templates."
60 | :type 'function
61 | :group 'org-starter)
62 |
63 | (defcustom org-starter-alternative-find-function
64 | (cond
65 | ((fboundp 'helm-org-rifle-files) #'helm-org-rifle-files)
66 | (t #'org-starter-sparse-tree-on-file))
67 | "An alternative function to find an Org file.
68 |
69 | This function is called by `org-starter-find-file-by-key' when
70 | a sequence of two universal arguments are given."
71 | :group 'org-starter
72 | :type 'function)
73 |
74 | (defcustom org-starter-use-child-frame t
75 | "If non-nil, use child frames for multi line messages.
76 |
77 | You will need posframe.el for actually using this feature."
78 | :type 'boolean
79 | :group 'org-starter)
80 |
81 | (defcustom org-starter-child-frame-border-width 2
82 | "Border width of child frames."
83 | :type 'number
84 | :group 'org-starter)
85 |
86 | (defcustom org-starter-child-frame-border-color
87 | "white"
88 | "Border color of child frames."
89 | :type 'color
90 | :group 'org-starter)
91 |
92 | (defcustom org-starter-child-frame-foreground-color nil
93 | "Border color of child frames."
94 | :type '(choice color nil)
95 | :group 'org-starter)
96 |
97 | (defcustom org-starter-child-frame-background-color nil
98 | "Border color of child frames."
99 | :type '(choice color nil)
100 | :group 'org-starter)
101 |
102 | (defcustom org-starter-child-frame-override-parameters nil
103 | "Override posframe parameters with this plist."
104 | :type 'plist
105 | :group 'org-starter)
106 |
107 | (defcustom org-starter-child-frame-poshandler
108 | #'posframe-poshandler-frame-center
109 | "Poshandler function."
110 | :type 'function
111 | :group 'org-starter)
112 |
113 | (defcustom org-starter-verify-agenda-configuration t
114 | "Whether to verify configuration in `org-starter-add-agenda-custom-command'."
115 | :type 'boolean
116 | :group 'org-starter)
117 |
118 | (define-widget 'org-starter-bindings 'lazy
119 | "List of custom keybindings."
120 | :tag "Keybindings"
121 | :type '(repeat (list (string :tag "Key")
122 | (function :tag "Command")
123 | (choice :tag "Help"
124 | string
125 | (const nil)))))
126 |
127 | (defcustom org-starter-find-file-visit-window
128 | nil
129 | "When non-nil, visit the window displaying a file if any.
130 |
131 | When this variable is set to non-nil,
132 | `org-starter-find-file-by-key' selects a window displaying the
133 | target file if there is such a window in the same frame."
134 | :type 'boolean
135 | :group 'org-starter)
136 |
137 | (defcustom org-starter-extra-find-file-map
138 | nil
139 | "Extra bindings available in `org-starter-find-file-by-key'."
140 | :group 'org-starter
141 | :type 'org-starter-bindings)
142 |
143 | (defcustom org-starter-extra-refile-map
144 | '(("/" org-refile "normal refile"))
145 | "Extra bindings available in `org-starter-refile-by-key'."
146 | :group 'org-starter
147 | :type 'org-starter-bindings)
148 |
149 | (defcustom org-starter-extra-alternative-find-file-map
150 | nil
151 | "Extra keybindings in `org-starter-alternative-find-file-by-key'."
152 | :group 'org-starter
153 | :type 'org-starter-bindings)
154 |
155 | (defcustom org-starter-require-file-by-default t
156 | "When non-nil, require defined files by default.
157 |
158 | This is the default value of \":required\" option in
159 | `org-starter-define-file'. If this option is non-nil,
160 | all files defined by org-starter must exist. If a file does not
161 | exist, it throws an error.
162 |
163 | This option does not affect the behavior of directory definitions."
164 | :group 'org-starter
165 | :type 'boolean)
166 |
167 | (defcustom org-starter-config-file-name ".org-config.el"
168 | "File name of external config files for org-starter.
169 |
170 | See function `org-starter-load-config-files' for details."
171 | :risky t
172 | :group 'org-starter
173 | :type 'string)
174 |
175 | (defcustom org-starter-load-config-files nil
176 | "When non-nil, load config files in known directories.
177 |
178 | Org-Starter loads configuration files with
179 | `org-starter-config-file-name' if this variable is set to non-nil.
180 |
181 | When this variable is set to non-nil, org-starter loads Emacs
182 | Lisp configuration files with from the following places:
183 |
184 | - When org-starter.el is loaded, org-starter loads configuration files
185 | in `org-starter-path'.
186 |
187 | - After org-starter.el is loaded, org-starter loads configuration
188 | files as directories are defined using
189 | `org-starter-define-directory' (or `org-starter-def' on a
190 | directory).
191 |
192 | If a file with `org-starter-config-file-name' does not exist in a
193 | given directory, the file will not be loaded."
194 | :group 'org-starter
195 | :type 'boolean)
196 |
197 | (defcustom org-starter-refresh-agenda-on-redefinition t
198 | "When non-nil, refresh an existing agenda buffer on redefinition.
199 |
200 | If you set this variable to non-nil, both
201 | `org-starter-add-agenda-custom-command' and
202 | `org-starter-add-block-agenda-command' refreshes a corresponding existing agenda
203 | buffer if it is updates an existing buffer of the same key.
204 | This is useful for experimenting with a new custom agenda command.
205 |
206 | If `org-agenda-sticky' is non-nil, it checks for a stick agenda
207 | buffer of the same key. If such a buffer exists, the buffer is
208 | killed and the agenda is redispatched.
209 |
210 | If `org-agenda-sticky' is nil, it checks if there is an agenda buffer
211 | and redispatches the redefined agenda, no matter which agenda command
212 | is currently displayed in the agenda buffer.
213 |
214 | If the value is \"confirm\" instead of t, it asks the user if he/she
215 | wants to redispatches the agenda."
216 | :group 'org-starter
217 | :type '(choice (const :tag "Without confirmation" t)
218 | (const :tag "With confirmation" confirm)
219 | (const :tag "Never" nil)))
220 |
221 | (defcustom org-starter-override-agenda-window-setup
222 | nil
223 | "If non-nil, override `org-agenda-window-setup' when redispatching an agenda.
224 |
225 | This is effective if and only if an agenda command is dispatched
226 | by org-starter as documented for
227 | `org-starter-refresh-agenda-on-redefinition'.
228 |
229 | If you are experimenting with a custom agenda command, you
230 | probably don't want to display the agenda in the same buffer as
231 | the source code. To handle such a situation, this option lets you
232 | override `org-agenda-window-setup' only when an agenda command is
233 | dispatched due to redefining it. The options are the same as
234 | `org-agenda-window-setup'.
235 |
236 | If this variable is nil, it doesn't take effect, and the same
237 | window setup is used."
238 | :group 'org-starter
239 | :type '(choice (const current-window)
240 | (const other-window)
241 | (const only-window)
242 | (const reorganize-frame)
243 | (const other-frame)
244 | (const nil)))
245 |
246 | (defcustom org-starter-check-truename t
247 | "Whether to compare file names according to true names.
248 |
249 | When this option is t, it compares file names by true names in
250 | several functions. This is accurate if you store org files in
251 | symlinked directories, but it is slower.
252 |
253 | Set the value to nil if your org files don't involve symlinks."
254 | :group 'org-starter
255 | :type 'boolean)
256 |
257 | ;;;; Variables
258 | (defvar org-starter-suppress-override-messages-once nil)
259 |
260 | ;;;; The error buffer and error logging
261 | ;; This is used by `org-starter-verify-configuration'.
262 |
263 | (defcustom org-starter-enable-local-variables nil
264 | "Override `enable-local-variables' when files are loaded.
265 |
266 | When this variable is set to a value other than nil and function
267 | `org-starter-mode' is turned on, `enable-local-variables' is set
268 | to the value temporarily when a file in `org-starter-known-files'
269 | is loaded. For example, if the variable is set to `:all', all
270 | local variables defined in the file are applied when it is loaded
271 | without confirmation. As variables defined in your own files are
272 | supposed to be safe, this is also usually safe. However, when
273 | this option is set to `:all', please don't add a file that can be
274 | edited by someone else, as local variables can bring
275 | vulnerability.
276 |
277 | When the variable is set to nil, org-starter does not override the
278 | value of `enable-local-variables`."
279 | :group 'org-starter
280 | :type 'symbol)
281 |
282 | (defconst org-starter-error-buffer "*org-starter errors*")
283 |
284 | (defvar org-starter-found-errors nil
285 | "Non-nil if an error is found while configuring org-starter.")
286 |
287 | (defvar org-starter-prevent-local-config-directories nil
288 | "List of directories from which config files shouldn't be loaded.
289 |
290 | This is updated by `org-starter-define-directory'.
291 | The user should not update this value.")
292 |
293 | (defvar org-starter-truename-cache nil
294 | "Hash table used to store true names of files and directories.")
295 |
296 | ;;;###autoload
297 | (define-minor-mode org-starter-mode
298 | "Turn on/off features of org-starter.
299 |
300 | This includes the following features:
301 |
302 | - Activate a function advice around `find-file-noselect', so
303 | `org-starter-enable-local-variables' option is respected.
304 |
305 | - When Org files are loaded, set file-local variables defined as
306 | :local-variables option in `org-starter-define-file'."
307 | :lighter " Org-Starter"
308 | :require 'org-starter
309 | :global t
310 | :group 'org-starter
311 | (cond
312 | ;; Turn on
313 | (org-starter-mode
314 | (add-hook 'org-mode-hook #'org-starter-org-mode-hook t)
315 | (advice-add #'find-file-noselect :around
316 | #'org-starter--ad-around-find-file-noselect))
317 | ;; Turn off
318 | (t
319 | (advice-remove #'find-file-noselect
320 | #'org-starter--ad-around-find-file-noselect)
321 | (remove-hook 'org-mode-hook #'org-starter-org-mode-hook))))
322 |
323 | (defun org-starter--clear-errors ()
324 | "Reset the status of the error buffer."
325 | (org-starter--when-let* ((buf (get-buffer org-starter-error-buffer)))
326 | (with-current-buffer buf
327 | (let ((inhibit-read-only t))
328 | (erase-buffer))))
329 | (setq org-starter-found-errors nil))
330 |
331 | (defun org-starter--create-error-buffer ()
332 | "Return the error buffer."
333 | (or (get-buffer org-starter-error-buffer)
334 | (with-current-buffer (generate-new-buffer org-starter-error-buffer)
335 | (local-set-key "q" 'quit-window)
336 | (local-set-key "g" 'org-starter-verify-configuration)
337 | (setq buffer-read-only t)
338 | (current-buffer))))
339 |
340 | (defun org-starter--log-error-no-newline (format-string &rest args)
341 | "Variant of `org-starter--log-error' that does not append a newline.
342 |
343 | FORMAT-STRING is the format spec, and ARGS are parameters."
344 | (declare (indent 0))
345 | (with-current-buffer (org-starter--create-error-buffer)
346 | (let ((inhibit-read-only t))
347 | (insert (apply #'format format-string args))))
348 | (setq org-starter-found-errors (1+ (or org-starter-found-errors 0))))
349 |
350 | (defun org-starter--log-error (format-string &rest args)
351 | "Like `message', but logs a string to `org-starter-error-buffer'.
352 |
353 | FORMAT-STRING is the format spec, and ARGS are parameters."
354 | (declare (indent 0))
355 | (org-starter--log-error-no-newline (concat format-string "\n") args))
356 |
357 | ;;;; File registry: known files and directories, path, deprecated files, etc.
358 | (defvar org-starter-known-files nil
359 | "List of files registered by `org-starter-define-file'.")
360 |
361 | (defcustom org-starter-path nil
362 | "List of directories from which org files are searched."
363 | :group 'org-starter
364 | :type '(repeat string)
365 | :risky t
366 | :set (lambda (key value)
367 | (if (featurep 'org-starter)
368 | (let ((added (-difference value (symbol-value key))))
369 | (set-default key value)
370 | (message "Add directories to org-starter-path: %s"
371 | (string-join added " "))
372 | (mapc #'load-file (org-starter--get-existing-config-files added)))
373 | (set-default key value))))
374 |
375 | (defvar org-starter-deprecated-files nil
376 | "List of deprecated org files currently existing.")
377 |
378 | (defvar org-starter-known-directories nil)
379 |
380 | (defun org-starter--lookup-known-file (filename)
381 | "Look up a FILENAME (without a directory) in `org-starter-known-files'."
382 | (car (cl-remove-if-not (lambda (fpath)
383 | (equal filename
384 | (file-name-nondirectory fpath)))
385 | org-starter-known-files)))
386 |
387 | (defun org-starter--search-file (filename &optional check-known-files)
388 | "Search FILENAME from `org-starter-path'.
389 |
390 | If CHECK-KNOWN-FILES is non-nil, `org-starter-known-files' is first checked for
391 | the FILENAME."
392 | (or (and check-known-files
393 | (org-starter--lookup-known-file filename))
394 | (cl-loop for dir in org-starter-path
395 | for fpath = (expand-file-name filename dir)
396 | when (file-exists-p fpath)
397 | return fpath)))
398 |
399 | (defun org-starter-locate-file (filename &optional directory check-known-files)
400 | "Search FILENAME from DIRECTORY and `org-starter-path' and return its path.
401 |
402 | This function returns an existing path to a file which has the same
403 | sans-directory file name as FILENAME. If such a file is not found, this
404 | function returns nil.
405 |
406 | If CHECK-KNOWN-FILES is non-nil, `org-starter-known-files' is first checked for
407 | the FILENAME."
408 | (cond
409 | ((file-name-absolute-p filename)
410 | (when (file-exists-p filename)
411 | filename))
412 | ((null directory)
413 | (org-starter--search-file filename check-known-files))
414 | (t
415 | (let* ((dir (cond
416 | ((stringp directory) directory)
417 | ((symbolp directory) (symbol-value directory))
418 | (t (error "Unsupported type of directory: %s"
419 | (prin1-to-string directory)))))
420 | (default-file (expand-file-name filename dir)))
421 | (if (file-exists-p default-file)
422 | default-file
423 | (let ((found-file (org-starter--search-file filename
424 | check-known-files)))
425 | (when (and found-file
426 | (yes-or-no-p (format "%s does not exist, but %s is found. Add it instead?"
427 | default-file found-file)))
428 | found-file)))))))
429 |
430 | (defun org-starter--to-symbol-list (obj)
431 | "Make a list of symbols from a symbol or a list.
432 |
433 | OBJ should be a symbol, or a list of symbols."
434 | (cond
435 | ((null obj) nil)
436 | ((symbolp obj) (list obj))
437 | ((listp obj) obj)))
438 |
439 | (cl-defun org-starter--file-member-p (file list &key expand)
440 | "Return non-nil if the file is included in the list.
441 |
442 | FILE is an absolute path to a file, and LIST is a list of files.
443 |
444 | If EXPAND is non-nil, use `expand-file-name' to expand abbreviate
445 | file names. It doesn't take effect if
446 | `org-starter-check-truename' is non-nil."
447 | (cond
448 | (org-starter-check-truename
449 | (cl-member file list :test #'equal
450 | :key #'org-starter--cached-truename))
451 | (expand
452 | (cl-member file list :test #'equal :key #'expand-file-name))
453 | (t
454 | (member file list))))
455 |
456 | (defun org-starter--cached-truename (file)
457 | "Return the true name of FILE, from a cache value if available."
458 | (unless org-starter-truename-cache
459 | (setq org-starter-truename-cache
460 | (make-hash-table :test #'equal)))
461 | (or (gethash file org-starter-truename-cache)
462 | (let ((truename (file-truename file)))
463 | (puthash file truename org-starter-truename-cache)
464 | truename)))
465 |
466 | ;;;; Exclude files in org-starter from recentf
467 |
468 | (defcustom org-starter-exclude-from-recentf nil
469 | "If non-nil, exclude items in `org-starter-known-files' from recentf."
470 | :group 'org-starter
471 | :type '(set (const :tag "Exclude known files" 'known-files)
472 | (const :tag "Exclude files in path" 'path)))
473 |
474 | (defun org-starter-recentf-excluded-p (file)
475 | "Return non-nil if FILE should be excluded from recentf."
476 | (and (string-match-p org-agenda-file-regexp file)
477 | (listp org-starter-exclude-from-recentf)
478 | org-starter-exclude-from-recentf
479 | (or (and (memq 'known-files org-starter-exclude-from-recentf)
480 | (org-starter--file-member-p (expand-file-name file)
481 | org-starter-known-files))
482 | (and (memq 'path org-starter-exclude-from-recentf)
483 | (org-starter--file-member-p (file-name-directory file)
484 | org-starter-path)))))
485 |
486 | (add-hook 'recentf-exclude #'org-starter-recentf-excluded-p t)
487 |
488 | ;;;; Defining directories
489 |
490 | (defvar org-starter-directory-origins nil
491 | "Alist of pairs of a directory and its origin.
492 |
493 | Each item in this alist is a cons of a path to a local directory and its origin
494 | repository URL.")
495 |
496 | (defun org-starter--clone (origin dest)
497 | "Clone a repository at ORIGIN to DEST."
498 | ;; TODO: check origin URL
499 | (process-lines "git" "clone" origin dest))
500 |
501 | (defun org-starter-clone-all ()
502 | "Clone all missing repositories specified in `org-starter-directory-origins'."
503 | (interactive)
504 | (cl-loop for (dest . origin) in org-starter-directory-origins
505 | unless (file-directory-p dest)
506 | do (org-starter--clone origin dest)))
507 |
508 | (defun org-starter--define-glob-function (dpath id)
509 | "Define a function to glob entries in a directory.
510 |
511 | This function defines a function to glob a list of org files in a directory.
512 | DPATH is a path to the directory, and ID is a symbol/string to uniquely
513 | identify the directory."
514 | (let ((name (intern (format "org-starter-glob-files/%s"
515 | (cl-etypecase id
516 | (symbol (symbol-name id))
517 | (string id))))))
518 | (eval `(defun ,name ()
519 | (when (file-directory-p ,dpath)
520 | (directory-files ,dpath t org-agenda-file-regexp))))))
521 |
522 | (cl-defun org-starter-define-directory (dpath &key
523 | agenda
524 | refile
525 | id
526 | origin
527 | ensure
528 | add-to-path
529 | custom-vars
530 | no-config-file
531 | files)
532 | "Define a directory for org files.
533 |
534 | DPATH is a path to the directory. This option cannot be nil.
535 |
536 | If AGENDA is non-nil, the directory is added to `org-agenda-files'.
537 |
538 | If REFILE is set, files in the directory are added to
539 | `org-refile-targets'. In this case, you have to also specify ID
540 | to uniquely identify the directory. This identifier is used to
541 | determine the name of a function to glob files in the directory,
542 | which is called by `org-refile'.
543 |
544 | ORIGIN is a repository URL from which you want to clone the
545 | repository. If this option is set and ENSURE option is non-nil,
546 | this function automatically clones the repository when the
547 | directory does not exist.
548 |
549 | If ADD-TO-PATH is non-nil, the directory is added to
550 | `org-starter-path'.
551 |
552 | CUSTOM-VARS can be either a symbol or a list of symbols.
553 | These symbols are names of variables that should be set to the path
554 | of the directory. `customize-set-variable' is used to set the value.
555 |
556 | If NO-CONFIG-FILE is set to non-nil, the configuration file in
557 | the directory will not be loaded even if
558 | `org-starter-load-config-files' is set and the directory contains
559 | the file.
560 |
561 | FILES is a list whose item accepts the same options as
562 | `org-starter-define-file', except for `:directory' option.
563 | You can define files in the directory.
564 |
565 | If the directory exists and the configuration is done properly,
566 | the path to the directory is returned as the result of this function."
567 | (declare (indent 1))
568 | (let ((exists (file-directory-p dpath)))
569 | (setq dpath (expand-file-name (file-name-as-directory dpath)))
570 | (when (and ensure (not exists))
571 | (unless origin
572 | (error "%s is a required directory, but `:ensure' property is unset" dpath))
573 | (org-starter--clone origin dpath))
574 | (when agenda
575 | (add-to-list 'org-agenda-files dpath 'append #'file-equal-p))
576 | (when origin
577 | (add-to-list 'org-starter-directory-origins (cons dpath origin)))
578 | (when (and add-to-path exists)
579 | (cl-adjoin dpath org-starter-path :test #'file-equal-p))
580 | (when refile
581 | (unless id
582 | (error "To add %s to refile targets, you must set `:id' property" dpath))
583 | (let* ((func (org-starter--define-glob-function dpath id))
584 | (pair (assq func org-refile-targets)))
585 | (if pair
586 | (setf (cdr pair) refile)
587 | (add-to-list 'org-refile-targets (cons func refile) 'append))))
588 | (dolist (symbol (cl-typecase custom-vars
589 | (list custom-vars)
590 | (symbol (list custom-vars))))
591 | (customize-set-variable symbol dpath))
592 | (when no-config-file
593 | (add-to-list 'org-starter-prevent-local-config-directories dpath))
594 | (cl-loop for (filename . options) in files
595 | do (apply #'org-starter-define-file filename :directory dpath
596 | options))
597 | (add-to-list 'org-starter-known-directories dpath)
598 | (when (and add-to-path
599 | after-init-time
600 | (not (cl-member dpath org-starter-prevent-local-config-directories
601 | :test #'file-equal-p)))
602 | (let ((file (expand-file-name org-starter-config-file-name dpath)))
603 | (when (file-exists-p file)
604 | (load-file file))))
605 | dpath))
606 |
607 | ;;;; Defining files
608 | ;;;;; File-local variables and modes
609 | (defvar org-starter-file-local-variables nil
610 | "Alist of file-local variable definitions.")
611 |
612 | (defvar org-starter-file-local-minor-modes nil
613 | "Alist of file-local minor modes.")
614 |
615 | (defvar org-starter-file-local-hooks nil
616 | "Alist of file-local load hooks.")
617 |
618 | (defun org-starter-org-mode-hook ()
619 | "Apply file-local settings."
620 | (org-starter--when-let* ((fpath (buffer-file-name)))
621 | (dolist (x (cdr (assoc fpath org-starter-file-local-variables)))
622 | (pcase x
623 | (`(,symbol . ,value)
624 | (cl-assert (symbolp symbol))
625 | (set (make-local-variable symbol) value))))
626 |
627 | (dolist (x (cdr (assoc fpath org-starter-file-local-minor-modes)))
628 | (pcase x
629 | ((pred symbolp) (funcall x 1))
630 | (`(,mode ,arg) (funcall mode arg))))
631 |
632 | (org-starter--when-let*
633 | ((hook (cdr (assoc fpath org-starter-file-local-hooks))))
634 | (funcall hook))))
635 |
636 | (define-obsolete-function-alias 'org-starter-load-local-variables
637 | #'org-starter-org-mode-hook
638 | "0.2.9")
639 |
640 | ;;;;; Keymap for visiting a known file (deprecated)
641 | (defvar org-starter-file-map (make-sparse-keymap)
642 | "Keymap used to find a file.")
643 |
644 | (defcustom org-starter-define-file-commands 'with-keys
645 | "Define commands to find a specific file.
646 |
647 | When non-nil, org-starter define commands to find (or jump to) a specific file
648 | defined by `org-starter-define-file'. The defined commands are also used to
649 | bind keys to files.
650 |
651 | This is convenient for the follwing
652 | reasons:
653 |
654 | - You can access a file quickly using \\[execute-command\\].
655 | - You can use the command names for which-key replacements."
656 | :group 'org-starter
657 | :type '(choice (const :tag "All defined files" all)
658 | (const :tag "Files with keys" with-keys)
659 | (const :tag "Never" nil)))
660 |
661 | (defcustom org-starter-file-command-template "org-starter-find-file:%s"
662 | "Template used to determine command names for files.
663 |
664 | '%s' in the template is replaced with the base name of the file.
665 |
666 | This is applicable when `org-starter-define-file-commands' is non-nil."
667 | :type 'string
668 | :group 'org-starter)
669 |
670 | (defmacro org-starter--file-command-name (fpath)
671 | "Build a command name for FPATH."
672 | `(intern (format org-starter-file-command-template (file-name-base ,fpath))))
673 |
674 | (defun org-starter--define-file-command (fpath)
675 | "Define a command to find FPATH."
676 | (eval
677 | `(defun ,(org-starter--file-command-name fpath) ()
678 | (interactive)
679 | (find-file ,fpath))))
680 |
681 | (defvar org-starter-key-file-alist nil)
682 |
683 | (defun org-starter--funcall-on-file-by-key (func &optional
684 | prompt
685 | extra-map
686 | extra-help)
687 | "Pick an Org file by key and apply a function on it.
688 |
689 | This function picks an Org file by a key specified as :key argument
690 | of `org-starter-define-file', and apply FUNC on it.
691 |
692 | If PROMPT is given, use it as the prompt.
693 |
694 | If EXTRA-MAP is given, use it as the extra map.
695 | The original bindings defined by :key property are overridden by it.
696 |
697 | EXTRA-HELP is an alist for the items in the extra map."
698 | (let* ((map (make-sparse-keymap))
699 | (message-log-max nil)
700 | (help-items (mapcar (lambda (cell)
701 | (format "[%s]: %s"
702 | (car cell) (cdr cell)))
703 | (cl-union extra-help
704 | (mapcar (lambda (cell)
705 | (cons (car cell)
706 | (file-name-nondirectory (cdr cell))))
707 | org-starter-key-file-alist)
708 | :key #'car))))
709 | (dolist (cell org-starter-key-file-alist)
710 | (define-key map (car cell)
711 | (lambda () (interactive) (funcall func (cdr cell)))))
712 | (org-starter--display-options prompt help-items)
713 | (set-transient-map (if extra-map
714 | (make-composed-keymap extra-map map)
715 | map))))
716 |
717 | ;;;###autoload
718 | (defun org-starter-find-file-by-key (&optional arg)
719 | "Visit an Org file quickly by key.
720 |
721 | With this command, you can quickly open a file by a key sequence
722 | specified as :key property of the file.
723 |
724 | To access a file which is not assigned a key, you can select it
725 | using `completing-read' by pressing \"/\" key.
726 |
727 | If a universal prefix is given as ARG, open the file in other
728 | window.
729 |
730 | If two universal prefix arguments (C-u C-u) is given, call a function
731 | specified as `org-starter-alternative-find-function' with the file
732 | as the argument."
733 | (interactive "P")
734 | (let* ((map (make-sparse-keymap))
735 | (extra-help (cl-loop for (key command . help) in org-starter-extra-find-file-map
736 | do (define-key map (kbd key) command)
737 | when help
738 | collect (cons key (car help)))))
739 | (pcase arg
740 | ('(4) (progn
741 | (define-key map (kbd "/") #'org-starter-select-file-other-window)
742 | (org-starter--funcall-on-file-by-key
743 | #'org-starter--find-file-other-window
744 | "Find an Org file in other window:"
745 | map extra-help)))
746 | ('(16) (progn
747 | (define-key map (kbd "/")
748 | (lambda ()
749 | (interactive)
750 | (funcall org-starter-alternative-find-function
751 | (org-starter-select-file "Select an Org file: "))))
752 | (org-starter--funcall-on-file-by-key
753 | org-starter-alternative-find-function
754 | (format "Call %s:"
755 | (if (symbolp org-starter-alternative-find-function)
756 | (symbol-name org-starter-alternative-find-function)
757 | "the function"))
758 | map extra-help)))
759 | (_ (progn
760 | (define-key map (kbd "/") #'org-starter-select-file)
761 | (org-starter--funcall-on-file-by-key
762 | #'org-starter--find-file
763 | "Find an Org file:"
764 | map extra-help))))))
765 |
766 | (defun org-starter--find-file (file)
767 | "Switch to a buffer visiting FILE."
768 | (org-starter--select-file-window file
769 | #'switch-to-buffer))
770 |
771 | (defun org-starter--find-file-other-window (file)
772 | "Switch to a buffer visiting FILE in other window."
773 | (org-starter--select-file-window file
774 | #'switch-to-buffer-other-window))
775 |
776 | (defun org-starter--select-file-window (file fallback)
777 | "Select a window displaying a file or open the file.
778 |
779 | If there is a window displaying the buffer of FILE, select the window.
780 | Otherwise, switch to the buffer of the file using FALLBACK function."
781 | (let ((buffer (or (find-buffer-visiting file)
782 | (find-file-noselect file))))
783 | (if-let ((window (and org-starter-find-file-visit-window
784 | (get-buffer-window buffer))))
785 | (select-window window)
786 | (funcall fallback buffer))))
787 |
788 | ;;;###autoload
789 | (defun org-starter-alternative-find-file-by-key (&optional arg)
790 | "Visit an Org file using `org-starter-alternative-find-function'.
791 |
792 | This is like `org-starter-find-file-by-key' but uses
793 | `org-starter-alternative-find-function' to visit a file.
794 | Keys are configured as :key properties of files, which are the same
795 | as `org-starter-find-file-by-key'.
796 |
797 | To access a file which is not assigned a key, you can select it
798 | using `completing-read' by pressing \"/\" key.
799 |
800 | If a universal prefix is given as ARG, visit the file using
801 | `find-file'.
802 |
803 | Extra commands are configured in
804 | `org-starter-extra-alternative-find-file-map'."
805 | (interactive "P")
806 | (let* ((map (make-sparse-keymap))
807 | (extra-help (cl-loop for (key command . help) in org-starter-extra-alternative-find-file-map
808 | do (define-key map (kbd key) command)
809 | when help
810 | collect (cons key (car help)))))
811 | (pcase arg
812 | ('(4) (progn
813 | (define-key map (kbd "/") #'org-starter-select-file)
814 | (org-starter--funcall-on-file-by-key
815 | #'find-file "Find an Org file:"
816 | map extra-help)))
817 | (_ (progn
818 | (define-key map (kbd "/") #'org-starter-select-file-alternative)
819 | (org-starter--funcall-on-file-by-key
820 | org-starter-alternative-find-function
821 | "Visit an Org file using the alternative command:"
822 | map extra-help))))))
823 |
824 | (defun org-starter--refile-target-of-file (file)
825 | "Get a refile target spec to FILE."
826 | (cl-assoc file (cl-remove-if-not (lambda (cell) (stringp (car cell)))
827 | org-refile-targets)
828 | :test 'file-equal-p))
829 |
830 | ;;;###autoload
831 | (defun org-starter-refile-by-key (&optional arg)
832 | "Run `org-refile' with the target limited to a file by key.
833 |
834 | With this command, you can quickly refile the current entry to a file by a key
835 | sequence specified as :key property of the file.
836 |
837 | ARG is passed to `org-refile' function.
838 |
839 | You can also access keybindings defined in
840 | `org-starter-extra-refile-map'.
841 | For example, you can run a normal `org-refile' by pressing \"/\" key
842 | by default."
843 | (interactive "P")
844 | (unless (derived-mode-p 'org-mode)
845 | (error "Not in org-mode"))
846 | (let* ((extra-map (make-sparse-keymap))
847 | (extra-help (cl-loop for (key command . help) in org-starter-extra-refile-map
848 | do (define-key extra-map (kbd key) command)
849 | when help
850 | collect (cons key (car help)))))
851 | (org-starter--funcall-on-file-by-key
852 | (lambda (file)
853 | (let ((org-refile-targets (list (or (org-starter--refile-target-of-file file)
854 | `(,file :maxlevel . 9)))))
855 | (org-refile arg)))
856 | "Refile to file:" extra-map extra-help)))
857 |
858 | (defun org-starter--bind-file-key (key fpath)
859 | "Bind KEY to a command to visit FPATH."
860 | ;; (let ((command-name (org-starter--file-command-name fpath)))
861 | ;; (define-key 'org-starter-file-map key
862 | ;; (if (and org-starter-define-file-commands
863 | ;; (fboundp command-name))
864 | ;; command-name
865 | ;; `(lambda () (interactive) (find-file ,fpath)))))
866 | (cl-pushnew (cons key fpath) org-starter-key-file-alist
867 | :key 'car :test 'equal))
868 |
869 | ;;;;; Defining a file
870 |
871 | (cl-defun org-starter-define-file (filename &key
872 | directory
873 | (required t)
874 | deprecated
875 | agenda
876 | refile
877 | custom-vars
878 | minor-modes
879 | set-default
880 | capture
881 | key
882 | local-variables
883 | local-config)
884 | "Define an org file.
885 |
886 | FILENAME is the file name of the org file. This can be either a file name
887 | without a directory or an absolute file path.
888 |
889 | DIRECTORY is a directory that should contain the file. FILENAME and DIRECTORY
890 | are passed to `org-starter-locate-file' function to find an actual path to the
891 | file.
892 |
893 | By default, this function raises an error if the file does not exist. This can
894 | be prevented by setting REQUIRED to nil or DEPRECATED to t.
895 |
896 | If DEPRECATED is non-nil, this file is not added to `org-refile-targets' even if
897 | the refile option is specified. The file is added to
898 | `org-starter-deprecated-files' which you can use for testing.
899 |
900 | If AGENDA is non-nil, the file is added to `org-agenda-files'.
901 |
902 | If REFILE is set, the file is added to `org-refile-targets' with the option
903 | value. For example, if you set REFILE to \"'(:maxlevel . 5)\", then
904 | \"'(PATH (:maxlevel . 5))\" is added to `org-refile-targets'.
905 |
906 | REFILE can be also a function. If it is a function, the function
907 | is used in `org-starter-refile-by-key'. See
908 | `org-starter-extras-def-reverse-datetree-refile' for example. You
909 | also have to specify KEY, and the file won't be added to
910 | `org-refile-targets'.
911 |
912 | If you specify variable names as a list of symbols in CUSTOM-VARS, those
913 | variables are set to the path of the defined file using
914 | `customize-set-variable'.
915 | For example, you can use this function to set `org-default-notes-file' based
916 | on the actual path.
917 |
918 | MINOR-MODES is a list of minor modes to turn on in the file. Each
919 | item is usually a symbol like `org-recur-mode', and in that case,
920 | the mode is turned on after the file is loaded. Alternatively, it
921 | can be a cell like \"(org-recur-mode -1)\" to ensure the mode is
922 | turned off in the file.
923 |
924 | SET-DEFAULT is almost the same as CUSTOM-VARS. It exists only for
925 | backwards-compatibility. It uses `set-default' instead of
926 | `customize-set-variable'.
927 |
928 | CAPTURE specifies a list of `org-capture' templates into the file.
929 | To properly override an existing template with the same key, items in
930 | `org-capture-templates' should be sorted lexicographically by key.
931 |
932 | KEY is a string to represent a key binding used to jump to the file.
933 | If this property is nil, the file will not be bound on the map.
934 |
935 | LOCAL-VARIABLES allows you to specify file-local variables which should be set
936 | after org-mode is initialized. This can be done in the file footer, but it is
937 | sometimes convenient to be able to define them outside of the file, especially
938 | if you define a complex function. This option should be an alist of variable
939 | names and values.
940 |
941 | LOCAL-CONFIG can be a function or an expression called or
942 | evaluated after the file is loaded. For example, you can call
943 | `add-hook' to add buffer-local hooks via this property.
944 |
945 | If the file exists and it is properly defined, the path to the file
946 | is returned as the result of this function."
947 | (declare (indent 1))
948 | (let ((fpath (org-starter-locate-file filename directory)))
949 | (cond
950 | (fpath (progn
951 | (when (cl-ecase org-starter-define-file-commands
952 | (all t)
953 | (with-keys key)
954 | (nil nil))
955 | (org-starter--define-file-command fpath))
956 | (when deprecated
957 | (org-starter--log-error "%s file is deprecated"
958 | (abbreviate-file-name fpath))
959 | (add-to-list 'org-starter-deprecated-files fpath))
960 | (if agenda
961 | (add-to-list 'org-agenda-files fpath 'append #'file-equal-p)
962 | (cl-delete fpath org-agenda-files :test #'file-equal-p))
963 | (mapc (lambda (symbol) (customize-set-variable symbol fpath))
964 | (org-starter--to-symbol-list custom-vars))
965 | (mapc (lambda (symbol) (set-default symbol fpath))
966 | (org-starter--to-symbol-list set-default))
967 | (when (and refile (not deprecated))
968 | (cl-etypecase refile
969 | (function
970 | (if key
971 | (let* ((item (list key refile filename))
972 | (cell (assoc (car item) org-starter-extra-refile-map)))
973 | (if cell
974 | (setcdr cell (cdr item))
975 | (push item org-starter-extra-refile-map)))
976 | (user-error "You have to specify KEY if REFILE is a function")))
977 | (list
978 | (let ((pair (assoc fpath org-refile-targets)))
979 | (if pair
980 | (setf (cdr pair) refile)
981 | (add-to-list 'org-refile-targets (cons fpath refile) 'append))))))
982 | (unless deprecated
983 | (dolist (spec (mapcar (or org-starter-capture-template-map-function
984 | #'identity)
985 | capture))
986 | (org-starter-add-file-capture-template fpath spec)))
987 | (when key
988 | (org-starter--bind-file-key key fpath))
989 | (when local-variables
990 | (push (cons fpath local-variables) org-starter-file-local-variables))
991 | (when minor-modes
992 | (push (cons fpath minor-modes) org-starter-file-local-minor-modes))
993 | (when local-config
994 | (push (cons fpath
995 | (cl-etypecase local-config
996 | (function local-config)
997 | ;; sexp
998 | (list `(lambda () ,local-config))))
999 | org-starter-file-local-hooks))
1000 | (add-to-list 'org-starter-known-files fpath)
1001 | fpath))
1002 | ((and (not deprecated)
1003 | org-starter-require-file-by-default
1004 | required)
1005 | (error "Required org file %s is not found" filename))
1006 | ((not deprecated)
1007 | (org-starter--log-error "%s is missing" filename)))))
1008 |
1009 | (defmacro org-starter-def (path &rest options)
1010 | "Define a file or a directory.
1011 |
1012 | This function calls either `org-starter-define-file' or
1013 | `org-starter-define-directory' depending on the type of the file at
1014 | PATH. PATH should be an absolute path.
1015 |
1016 | OPTIONS are passed to the function after preprocessing.
1017 |
1018 | As well as options to one of those functions, `org-starter-def'
1019 | supports an additional option \":config\", which is evaluated after
1020 | the file/directory is defined. This accepts multiple arguments."
1021 | (declare (indent 1))
1022 | (setq options (org-starter--flatten-plist options))
1023 | (let ((config (plist-get options :config)))
1024 | (cl-remf options :config)
1025 | `(if (file-directory-p ,path)
1026 | (let ((r (apply #'org-starter-define-directory
1027 | ,path
1028 | (quote ,options))))
1029 | ,@config
1030 | r)
1031 | (when-let ((path (org-starter-locate-file ,path
1032 | (plist-get (quote ,options)
1033 | :directory)))
1034 | (r (apply #'org-starter-define-file
1035 | path
1036 | (quote ,options))))
1037 | ,@config
1038 | r))))
1039 |
1040 | (defun org-starter--flatten-plist (plist)
1041 | "Flatten PLIST for use in `org-starter-def'."
1042 | (let (result
1043 | arg)
1044 | (while (setq arg (pop plist))
1045 | (pcase arg
1046 | (:config
1047 | (-let [(args plist2) (-split-with (-not #'org-starter--plist-keyword-p) plist)]
1048 | (setq plist plist2)
1049 | (push arg result)
1050 | (push args result)))
1051 | (:files
1052 | (-let [(args plist2) (-split-with (-not #'org-starter--plist-keyword-p) plist)]
1053 | (setq plist plist2)
1054 | (push arg result)
1055 | (push (org-starter--files-arg args) result)))
1056 | ((pred org-starter--plist-keyword-p)
1057 | (progn
1058 | (push arg result)
1059 | (push (pop plist) result)))))
1060 | (nreverse result)))
1061 |
1062 | (defun org-starter--files-arg (args)
1063 | "Normalize ARGS given as \":files\" option."
1064 | (if (and (= 1 (length args))
1065 | (listp (caar args)))
1066 | (car args)
1067 | args))
1068 |
1069 | (defun org-starter--plist-keyword-p (arg)
1070 | "Return non-nil if ARG is a symbol starting with \":\"."
1071 | (and (symbolp arg)
1072 | (string-equal (substring (symbol-name arg) 0 1) ":")))
1073 |
1074 | (defun org-starter--add-capture-template (spec)
1075 | "Insert SPEC into `org-capture-templates'."
1076 | (cl-destructuring-bind
1077 | (former latter)
1078 | (--split-with (string< (car it) (car spec))
1079 | org-capture-templates)
1080 | (setq org-capture-templates
1081 | `(,@former
1082 | ,spec
1083 | ,@(if (string-equal (caar latter) (car spec))
1084 | (cdr latter)
1085 | latter)))
1086 | ;; Return information during interactive evaluation
1087 | (when after-init-time
1088 | (and (string-equal (caar latter) (car spec))
1089 | (cons (cadr (car latter)) (cadr spec))))))
1090 |
1091 | (defcustom org-starter-initial-capture-templates nil
1092 | "List of capture templates unassociated with files.
1093 |
1094 | This is basically the same as `org-capture-templates', but when you
1095 | set this variable using the customization interface, it doesn't delete
1096 | existing capture templates. This is convenient for developing
1097 | templates with non-file targets when you have some templates defined
1098 | by `org-starter-define-file'."
1099 | ;; This type definition is copied from org-capture.el
1100 | :type
1101 | (let ((file-variants '(choice :tag "Filename "
1102 | (file :tag "Literal")
1103 | (function :tag "Function")
1104 | (variable :tag "Variable")
1105 | (sexp :tag "Form"))))
1106 | `(repeat
1107 | (choice :value ("" "" entry (file "~/org/notes.org") "")
1108 | (list :tag "Multikey description"
1109 | (string :tag "Keys ")
1110 | (string :tag "Description"))
1111 | (list :tag "Template entry"
1112 | (string :tag "Keys ")
1113 | (string :tag "Description ")
1114 | (choice :tag "Capture Type " :value entry
1115 | (const :tag "Org entry" entry)
1116 | (const :tag "Plain list item" item)
1117 | (const :tag "Checkbox item" checkitem)
1118 | (const :tag "Plain text" plain)
1119 | (const :tag "Table line" table-line))
1120 | (choice :tag "Target location"
1121 | (list :tag "File"
1122 | (const :format "" file)
1123 | ,file-variants)
1124 | (list :tag "ID"
1125 | (const :format "" id)
1126 | (string :tag " ID"))
1127 | (list :tag "File & Headline"
1128 | (const :format "" file+headline)
1129 | ,file-variants
1130 | (string :tag " Headline"))
1131 | (list :tag "File & Outline path"
1132 | (const :format "" file+olp)
1133 | ,file-variants
1134 | (repeat :tag "Outline path" :inline t
1135 | (string :tag "Headline")))
1136 | (list :tag "File & Regexp"
1137 | (const :format "" file+regexp)
1138 | ,file-variants
1139 | (regexp :tag " Regexp"))
1140 | (list :tag "File [ & Outline path ] & Date tree"
1141 | (const :format "" file+olp+datetree)
1142 | ,file-variants
1143 | (option (repeat :tag "Outline path" :inline t
1144 | (string :tag "Headline"))))
1145 | (list :tag "File & function"
1146 | (const :format "" file+function)
1147 | ,file-variants
1148 | (sexp :tag " Function"))
1149 | (list :tag "Current clocking task"
1150 | (const :format "" clock))
1151 | (list :tag "Function"
1152 | (const :format "" function)
1153 | (sexp :tag " Function")))
1154 | (choice :tag "Template "
1155 | (string)
1156 | (list :tag "File"
1157 | (const :format "" file)
1158 | (file :tag "Template file"))
1159 | (list :tag "Function"
1160 | (const :format "" function)
1161 | (function :tag "Template function")))
1162 | (plist :inline t
1163 | ;; Give the most common options as checkboxes
1164 | :options (((const :format "%v " :prepend) (const t))
1165 | ((const :format "%v " :immediate-finish) (const t))
1166 | ((const :format "%v " :jump-to-captured) (const t))
1167 | ((const :format "%v " :empty-lines) (const 1))
1168 | ((const :format "%v " :empty-lines-before) (const 1))
1169 | ((const :format "%v " :empty-lines-after) (const 1))
1170 | ((const :format "%v " :clock-in) (const t))
1171 | ((const :format "%v " :clock-keep) (const t))
1172 | ((const :format "%v " :clock-resume) (const t))
1173 | ((const :format "%v " :time-prompt) (const t))
1174 | ((const :format "%v " :tree-type) (const week))
1175 | ((const :format "%v " :unnarrowed) (const t))
1176 | ((const :format "%v " :table-line-pos) (string))
1177 | ((const :format "%v " :kill-buffer) (const t))))))))
1178 | :group 'org-starter
1179 | :set (lambda (symbol value)
1180 | (set-default symbol value)
1181 | (mapc #'org-starter--add-capture-template
1182 | (cl-sort value #'string< :key #'car))))
1183 |
1184 | ;;;###autoload
1185 | (defun org-starter-undefine-file (filename)
1186 | "Delete an entry with FILENAME from the list of known files."
1187 | (interactive (list (completing-read "Known file to undefine: "
1188 | org-starter-known-files nil t)))
1189 | (let ((fpath (expand-file-name
1190 | (cond
1191 | ((file-name-absolute-p filename) filename)
1192 | (t (org-starter--lookup-known-file filename))))))
1193 | (cl-delete fpath org-starter-deprecated-files)
1194 | (cl-delete fpath org-agenda-files)
1195 | (cl-delete fpath org-refile-targets :key #'car)
1196 | (cl-delete fpath org-capture-templates
1197 | :test #'equal
1198 | :key (lambda (spec)
1199 | (pcase (nth 3 spec)
1200 | (`(file ,fpath) fpath)
1201 | (`(,key ,fpath . ,_)
1202 | (when (string-prefix-p "file+"
1203 | (symbol-name key))
1204 | fpath)))))
1205 | (cl-delete fpath org-starter-known-files)
1206 | (message "Deleted %s from org-starter-known-files" fpath)))
1207 |
1208 | ;;;;; Configure a particular aspect of a file
1209 | (defun org-starter-add-file-capture-template (file spec)
1210 | "Add a capture template for an already defined file.
1211 |
1212 | FILE is a file name or a file path as passed to `org-starter-locate-file'
1213 | as the first argument.
1214 |
1215 | SPEC is the same as an item in :capture option of `org-starter-define-file'."
1216 | (declare (indent 1))
1217 | (let* ((fpath (org-starter-locate-file file nil t))
1218 | (target (pcase (nth 3 spec)
1219 | ('file `(file ,fpath))
1220 | (`(file+headline ,headline) `(file+headline ,fpath ,headline))
1221 | (`(file+olp . ,olp) `(file+olp ,fpath ,@olp))
1222 | (`(file+regexp ,regexp)
1223 | `(file+regexp ,fpath ,regexp))
1224 | (`(file+olp+datetree . ,olp)
1225 | `(file+olp+datetree ,fpath ,@olp))
1226 | (`(file+function ,function)
1227 | `(file+function ,fpath ,function))
1228 | (orig orig))))
1229 | ;; Override the target if and only if it has one
1230 | ;; The spec can be a list of two elements, i.e. a group
1231 | (when target
1232 | (setf (car (nthcdr 3 spec)) target))
1233 | (org-starter--add-capture-template spec)))
1234 |
1235 | (cl-defmacro org-starter-def-capture (keys
1236 | description
1237 | &optional
1238 | type
1239 | target
1240 | template
1241 | &key
1242 | prepend
1243 | immediate-finish
1244 | jump-to-captured
1245 | empty-lines
1246 | empty-lines-before
1247 | empty-lines-after
1248 | clock-in
1249 | clock-keep
1250 | clock-resume
1251 | time-prompt
1252 | tree-type
1253 | unnarrowed
1254 | table-line-pos
1255 | kill-buffer
1256 | no-save
1257 | &allow-other-keys)
1258 | "Define a single capture template to a known file.
1259 |
1260 | This macro lets you insert an entry into
1261 | `org-capture-templates'. The resulting template list will be
1262 | sorted by alphabetical order, so templates are grouped with
1263 | prefix letters.
1264 |
1265 | It has the same functionality as
1266 | `org-starter-add-file-capture-template', but this is intended to
1267 | provide a better API.
1268 |
1269 | KEYS, DESCRIPTION, and TYPE are basically the same as in
1270 | `org-capture-templates' variable. However, KEYS can also be a symbol
1271 | whose variable is a string.
1272 |
1273 | TARGET is almost the same, but if the template type is a file or
1274 | part of it, e.g. \"file+headline\", the file name in the
1275 | expression is replaced with its absolute path as given by
1276 | `org-starter-locate-file'.
1277 |
1278 | TEMPLATE is the same.
1279 |
1280 | You can pass the following options as a plist as in
1281 | `org-capture-templates':
1282 |
1283 | PREPEND, IMMEDIATE-FINISH, JUMP-TO-CAPTURED, EMPTY-LINES,
1284 | EMPTY-LINES-BEFORE, EMPTY-LINES-AFTER, CLOCK-IN, CLOCK-KEEP,
1285 | CLOCK-RESUME, TIME-PROMPT, TREE-TYPE, UNNARROWED, TABLE-LINE-POS,
1286 | KILL-BUFFER, and NO-SAVE.
1287 |
1288 | The entire template spec is transformed by
1289 | `org-starter-capture-template-map-function'.
1290 |
1291 | If TYPE and its following arguments are omitted, this macro inserts
1292 | a template group."
1293 | (declare (indent 2))
1294 | ;; If KEYS is a symbol, use its value as the key sequence.
1295 | (when (symbolp keys)
1296 | (setq keys (symbol-value keys)))
1297 | (let* ((ok t)
1298 | (target1 (pcase target
1299 | (`(file ,file)
1300 | `(file ,(setq ok (if (stringp file)
1301 | (org-starter-locate-file file nil t)
1302 | file))))
1303 | (`(file+headline ,file ,headline)
1304 | `(file+headline ,(setq ok (if (stringp file)
1305 | (org-starter-locate-file file nil t)
1306 | file)) ,headline))
1307 | (`(file+olp ,file . ,olp)
1308 | `(file+olp ,(setq ok (if (stringp file)
1309 | (org-starter-locate-file file nil t)
1310 | file)) ,@olp))
1311 | (`(file+regexp ,file ,regexp)
1312 | `(file+regexp ,(setq ok (if (stringp file)
1313 | (org-starter-locate-file file nil t)
1314 | file)) ,regexp))
1315 | (`(file+olp+datetree ,file . ,olp)
1316 | `(file+olp+datetree ,(setq ok (if (stringp file)
1317 | (org-starter-locate-file file nil t)
1318 | file)) ,@olp))
1319 | (`(file+function ,file ,function)
1320 | `(file+function ,(setq ok (if (stringp file)
1321 | (org-starter-locate-file file nil t)
1322 | file)) ,function))
1323 | (orig orig)))
1324 | (properties (-flatten-n
1325 | 1 (--filter (nth 1 it)
1326 | `((:prepend ,prepend)
1327 | (:immediate-finish ,immediate-finish)
1328 | (:jump-to-captured ,jump-to-captured)
1329 | (:empty-lines ,empty-lines)
1330 | (:empty-lines-before ,empty-lines-before)
1331 | (:empty-lines-after ,empty-lines-after)
1332 | (:clock-in ,clock-in)
1333 | (:clock-keep ,clock-keep)
1334 | (:clock-resume ,clock-resume)
1335 | (:time-prompt ,time-prompt)
1336 | (:tree-type ,tree-type)
1337 | (:unnarrowed ,unnarrowed)
1338 | (:table-line-pos ,table-line-pos)
1339 | (:kill-buffer ,kill-buffer)
1340 | (:no-save ,no-save)))))
1341 | (spec (if type
1342 | (funcall (or org-starter-capture-template-map-function
1343 | #'identity)
1344 | (append (list keys description type target1 template)
1345 | properties))
1346 | (list keys description))))
1347 | (when ok
1348 | `(when-let ((result (org-starter--add-capture-template (quote ,spec))))
1349 | (concat "Overrode an existing template "
1350 | (if (string-equal (car result) (cdr result))
1351 | "of the same name"
1352 | (format "'%s'" (car result))))))))
1353 |
1354 | ;;;; Org-agenda
1355 | (defvar org-starter-suppress-override-messages-once nil)
1356 |
1357 | ;;;###autoload
1358 | (defun org-starter-add-agenda-custom-command (key desc
1359 | &optional
1360 | type match settings files)
1361 | "`org-add-agenda-custom-command' with extra features.
1362 |
1363 | This function basically adds (KEY DESC TYPE MATCH SETTINGS FILES) to
1364 | `org-agnda-custom-commands', but if it also checks if KEY does not
1365 | conflict with existing custom agenda commands.
1366 |
1367 | You can also define a group using this function by omitting TYPE,
1368 | MATCH, SETTINGS, and FILES passed to it.
1369 |
1370 | Some extra features may be added in the future."
1371 | (declare (indent 2))
1372 | ;; (unless (and key desc)
1373 | ;; (user-error "You cannot omit KEY and DESC"))
1374 | (when (and (featurep 'org-starter)
1375 | org-starter-verify-agenda-configuration)
1376 | (unless (stringp key)
1377 | (user-error "KEY must be a string"))
1378 | (unless (stringp desc)
1379 | (user-error "DESC must be a string"))
1380 | ;; TODO: Verify match, settings, and files
1381 | (org-starter--verify-agenda-type type t))
1382 | (let ((args (let ((args (list type match settings files)))
1383 | (nreverse (-drop-while #'not (nreverse args))))))
1384 | (if-let ((current (assoc key org-agenda-custom-commands))
1385 | (old-desc (nth 1 current)))
1386 | ;; If it has the same description, override it
1387 | (when (or (string-equal desc old-desc)
1388 | (not after-init-time)
1389 | org-starter-suppress-override-messages-once
1390 | ;; Otherwise, confirmation is needed
1391 | (yes-or-no-p (format "Replace custom agenda command '%s' with '%s'?"
1392 | old-desc desc)))
1393 | (setcdr current (cons desc args))
1394 | (when org-starter-refresh-agenda-on-redefinition
1395 | (cond
1396 | (org-agenda-sticky
1397 | (let ((sticky-agenda-buffer (get-buffer (format "*Org Agenda(%s)*" key))))
1398 | (when (and sticky-agenda-buffer
1399 | (or (not (eq 'confirm org-starter-refresh-agenda-on-redefinition))
1400 | (yes-or-no-p (format "Kill existing sticky agenda buffer %s and rerun it?" key))))
1401 | (let ((agenda-window (get-buffer-window sticky-agenda-buffer t))
1402 | (orig-buffer (window-buffer)))
1403 | (unwind-protect
1404 | (if agenda-window
1405 | (with-selected-window agenda-window
1406 | (kill-buffer sticky-agenda-buffer)
1407 | (let ((org-agenda-window-setup 'current-window))
1408 | (org-agenda nil key)))
1409 | (kill-buffer sticky-agenda-buffer)
1410 | (org-agenda nil key))
1411 | (if-let ((orig-window (get-buffer-window orig-buffer)))
1412 | (select-window orig-window)
1413 | (switch-to-buffer orig-buffer)))))))
1414 | ((and (get-buffer org-agenda-buffer-name)
1415 | (or (not (eq 'confirm org-starter-refresh-agenda-on-redefinition))
1416 | (yes-or-no-p (format "Run agenda %s immediately?" key))))
1417 | (let ((agenda-window (get-buffer-window org-agenda-buffer-name t))
1418 | (orig-buffer (window-buffer)))
1419 | (unwind-protect
1420 | (if agenda-window
1421 | (with-selected-window agenda-window
1422 | (let ((org-agenda-window-setup 'current-window))
1423 | (org-agenda nil key)))
1424 | (org-starter-agenda-with-window-setup nil key))
1425 | (if-let ((orig-window (get-buffer-window orig-buffer)))
1426 | (select-window orig-window)
1427 | (switch-to-buffer orig-buffer)))))))
1428 | `(,key ,desc ,@args))
1429 | (push `(,key ,desc ,@args) org-agenda-custom-commands))))
1430 |
1431 | (defun org-starter--agenda-current-window (&rest args)
1432 | "Call `org-agenda' with ARGS in the current window."
1433 | (let ((orig-value org-agenda-window-setup))
1434 | (setq org-agenda-window-setup 'current-window)
1435 | (unwind-protect
1436 | (apply #'org-agenda args)
1437 | (setq org-agenda-window-setup orig-value))))
1438 |
1439 | (defun org-starter-agenda-with-window-setup (&rest args)
1440 | "Run `org-agenda' with ARGS with `org-starter-override-agenda-window-setup'."
1441 | (let ((orig-buffer (window-buffer))
1442 | (org-agenda-window-setup (or org-starter-override-agenda-window-setup
1443 | org-agenda-window-setup)))
1444 | (apply #'org-agenda args)
1445 | (select-window (get-buffer-window orig-buffer))))
1446 |
1447 | ;;;###autoload
1448 | (cl-defun org-starter-add-block-agenda-command (key desc
1449 | &rest list-of-type-match-settings-files
1450 | &key settings files
1451 | &allow-other-keys)
1452 | "Define a block agenda.
1453 |
1454 | An entry consisting KEY, DESC, LIST-OF-TYPE-MATCH-SETTINGS-FILES,
1455 | SETTINGS, and FILES are added to `org-agenda-custom-commands'."
1456 | (declare (indent 2))
1457 | (cl-remf list-of-type-match-settings-files :settings)
1458 | (cl-remf list-of-type-match-settings-files :files)
1459 | (org-starter-add-agenda-custom-command key desc
1460 | list-of-type-match-settings-files settings files))
1461 |
1462 | (defconst org-starter-agenda-allowed-types
1463 | '(agenda todo search tags-tags-todo todo-tree tags-tree))
1464 |
1465 | (defun org-starter--verify-agenda-type (type &optional verbose)
1466 | "Check if an agenda type is an allowed value.
1467 |
1468 | This function checks if TYPE is a value allowed in
1469 | `org-agenda-custom-commands'.
1470 |
1471 | If the value is correct, the function returns non-nil.
1472 |
1473 | If VERBOSE is non-nil, displays an error instead if returning
1474 | nil."
1475 | (or (or (member type org-starter-agenda-allowed-types)
1476 | (functionp type)
1477 | ;; block agenda
1478 | (listp type))
1479 | (and verbose
1480 | (user-error "An agenda TYPE must be one of %s, a function, or a list"
1481 | org-starter-agenda-allowed-types))))
1482 |
1483 | ;;;; File operations
1484 |
1485 | ;;;###autoload
1486 | (defun org-starter-add-to-refile-targets ()
1487 | "Add the current buffer to `org-refile-targets' temporarily."
1488 | (interactive)
1489 | (unless (derived-mode-p 'org-mode)
1490 | (user-error "Not in org-mode"))
1491 | (if-let ((filename (buffer-file-name)))
1492 | (when (or (not (cl-member filename org-refile-targets
1493 | :test #'file-equal-p))
1494 | (yes-or-no-p (message "org-refile-targets already includes %s.\nAre you sure you want to override the entry?"
1495 | filename)))
1496 | (cl-case (read-char "Refile target type [l: level, m: maxlevel, q: tag, t: todo, r: regexp]: ")
1497 | (?l (org-starter--add-refile-target filename
1498 | `(:level . ,(org-starter--read-refile-level))))
1499 | (?m (org-starter--add-refile-target filename
1500 | `(:maxlevel . ,(org-starter--read-refile-level))))
1501 | (?q (org-starter--add-refile-target filename
1502 | `(:tag . ,(org-starter--read-refile-level))))
1503 | (?t (org-starter--add-refile-target filename
1504 | `(:tag . ,(org-starter--read-refile-level))))
1505 | (?r (org-starter--add-refile-target filename
1506 | `(:regexp . ,(org-starter--read-refile-level))))))
1507 | (user-error "Not visiting a file")))
1508 |
1509 | (defun org-starter--read-refile-level ()
1510 | "Read a character between 0 and 9 and return the number."
1511 | (let ((level-char (read-char "Refile level [0-9]: ")))
1512 | (if (and (>= level-char ?0) (<= level-char ?9))
1513 | (- level-char ?0)
1514 | (user-error "Please enter a character between 0 and 9"))))
1515 |
1516 | (defun org-starter--read-tag (prompt)
1517 | "Read Org tag with PROMPT."
1518 | (completing-read prompt 'org-tags-completion-function))
1519 |
1520 | (defun org-starter--add-refile-target (filename spec)
1521 | "Add a pair of FILENAME and SPEC to `org-refile-targets'."
1522 | (declare (indent 1))
1523 | (let ((existing (cl-assoc filename org-refile-targets :test #'file-equal-p)))
1524 | (if existing
1525 | (push (cons filename spec) org-refile-targets)
1526 | (setcdr existing spec))))
1527 |
1528 | ;;;; Miscellaneous functionality
1529 |
1530 | ;;;###autoload
1531 | (defun org-starter-cleanup-entries (&optional all)
1532 | "Remove missing files and directories from various variables.
1533 |
1534 | This function removes files and directories that no longer exists from the
1535 | following variables:
1536 |
1537 | - `org-starter-known-directories'
1538 | - `org-starter-known-files'
1539 |
1540 | If ALL is non-nil, variable `org-agenda-files' and
1541 | `org-refile-targets' are also checked for missing entries."
1542 | (interactive "P")
1543 | (cl-remove-if-not #'file-directory-p org-starter-known-directories)
1544 | (cl-remove-if-not #'file-exists-p org-starter-known-files)
1545 | (when all
1546 | (cl-remove-if-not #'file-exists-p org-agenda-files)
1547 | (cl-remove-if (lambda (pair)
1548 | (let ((path (car pair)))
1549 | (and (stringp path)
1550 | (not (file-exists-p path)))))
1551 | org-refile-targets)))
1552 |
1553 | ;;;###autoload
1554 | (defun org-starter-verify-configuration ()
1555 | "Check the current configuration."
1556 | (interactive)
1557 | (org-starter--clear-errors)
1558 | (cl-loop for fpath in org-starter-known-files
1559 | unless (file-exists-p fpath)
1560 | do (when (yes-or-no-p (format "%s no longer exists. Delete it from the known file list?"
1561 | fpath))
1562 | (org-starter-undefine-file fpath)))
1563 | (org-starter--when-let* ((deprecated-files (cl-remove-if-not #'file-exists-p
1564 | org-starter-deprecated-files)))
1565 | (org-starter--log-error-no-newline "%d deprecated files still exist:\n%s"
1566 | (length deprecated-files)
1567 | (cl-loop for fpath in deprecated-files
1568 | concat (format "- %s\n"
1569 | (abbreviate-file-name fpath)))))
1570 | (if org-starter-found-errors
1571 | (progn
1572 | (pop-to-buffer org-starter-error-buffer)
1573 | (message "%d errors found" org-starter-found-errors))
1574 | (message "No error")))
1575 |
1576 | (defun org-starter-sparse-tree-on-file (file)
1577 | "Run `org-sparse-tree' on FILE."
1578 | (find-file file)
1579 | (call-interactively #'org-sparse-tree))
1580 |
1581 | ;;;; Loading files
1582 |
1583 | (defun org-starter--load-file (fpath)
1584 | "If there is no buffer visiting FPATH, load it into Emacs.
1585 |
1586 | Unlike `find-file-noselect', this function does not care about changes in files
1587 | that are already loaded."
1588 | (unless (find-buffer-visiting fpath)
1589 | (let* ((default-directory (file-name-directory fpath))
1590 | (enable-local-variables (or org-starter-enable-local-variables
1591 | enable-local-variables))
1592 | (buf (find-file-noselect fpath)))
1593 | ;; TODO: Set options
1594 | ;; (with-current-buffer buf)
1595 | buf)))
1596 |
1597 | (defun org-starter--ad-around-find-file-noselect (orig filename &rest args)
1598 | "Advice around `find-file-noselect'.
1599 |
1600 | ORIG is the original function of `find-file-noselect'.
1601 |
1602 | If FILENAME is an Org file as defined by `org-agenda-file-regexp'
1603 | and included in `org-starter-known-files', the adviced function
1604 | alternates the value of `enable-local-variables' variable so
1605 | `org-starter-enable-local-variables' is respected.
1606 |
1607 | ARGS is the rest of arguments passed to the function."
1608 | (if (and (string-match-p org-agenda-file-regexp filename)
1609 | (cl-member filename org-starter-known-files :test #'file-equal-p))
1610 | (let* ((enable-local-variables
1611 | (or org-starter-enable-local-variables
1612 | (let ((default-directory (file-name-directory filename)))
1613 | enable-local-variables))))
1614 | (apply orig filename args))
1615 | (apply orig filename args)))
1616 |
1617 | (cl-defun org-starter--complete-file (prompt &key exclude-loaded-files)
1618 | "Select a known file or an agenda file using `completing-read'.
1619 |
1620 | PROMPT is the prompt displayed in the selection interface.
1621 |
1622 | When EXCLUDE-LOADED-FILES is set to non-nil, exclude files that have
1623 | been loaded."
1624 | (expand-file-name
1625 | (completing-read prompt
1626 | (cl-remove-if
1627 | (lambda (fpath)
1628 | (and exclude-loaded-files
1629 | (find-buffer-visiting fpath)))
1630 | (cl-remove-duplicates
1631 | (mapcar #'abbreviate-file-name
1632 | (append org-starter-known-files
1633 | (org-agenda-files)))
1634 | :test #'string-equal))
1635 | nil 'require-match)))
1636 |
1637 | ;;;###autoload
1638 | (defun org-starter-select-file (prompt)
1639 | "Select a file from known files and agenda files.
1640 |
1641 | This function select an Org file using `completing-read' with PROMPT.
1642 |
1643 | If this function is called interactively, it visits the selected file.
1644 | If a prefix argument is given, it visits the selected file in
1645 | other window.
1646 |
1647 | If this function is called non-interactively, it returns the file path
1648 | of the selected file."
1649 | (interactive
1650 | (list "Select an Org file: "))
1651 | (let ((file (org-starter--complete-file prompt)))
1652 | (if (called-interactively-p nil)
1653 | (if current-prefix-arg
1654 | (find-file-other-window file)
1655 | (find-file file))
1656 | file)))
1657 |
1658 | ;;;###autoload
1659 | (defun org-starter-select-file-other-window ()
1660 | "A variant of `org-starter-select-file' targetting other window."
1661 | (interactive)
1662 | (find-file-other-window
1663 | (org-starter-select-file "Select an Org file in other window: ")))
1664 |
1665 | ;;;###autoload
1666 | (defun org-starter-select-file-alternative ()
1667 | "Select a file and visit it using the alternative command.
1668 |
1669 | This function behaves like `org-starter-select-file' but uses
1670 | `org-starter-alternative-find-function' to visit a selected file."
1671 | (interactive)
1672 | (funcall org-starter-alternative-find-function
1673 | (org-starter--complete-file
1674 | "Visit a file using the alternative command: ")))
1675 |
1676 | ;;;###autoload
1677 | (defun org-starter-load-file (file)
1678 | "Load FILE using org-starter."
1679 | (interactive (list (org-starter--complete-file "Load an Org file: "
1680 | :exclude-loaded-files t)))
1681 | (if (cl-member file org-starter-known-files :test #'file-equal-p)
1682 | (org-starter--load-file file)
1683 | (error "%s is not in org-starter-known-files" file)))
1684 |
1685 | ;;;###autoload
1686 | (defun org-starter-load-all-known-files ()
1687 | "Load all files registered in `org-starter-known-files' into Emacs.
1688 |
1689 | This can be convenient in some situations where you want ensure that all org
1690 | files are in buffers."
1691 | (interactive)
1692 | (mapc #'org-starter--load-file org-starter-known-files))
1693 |
1694 | (defun org-starter-get-all-files-in-path ()
1695 | "Get a list of org files in `org-starter-path'.
1696 |
1697 | `org-agenda-file-regexp' is used to match the files."
1698 | (cl-loop for dpath in org-starter-path
1699 | append (directory-files dpath t org-agenda-file-regexp)))
1700 |
1701 | ;;;###autoload
1702 | (defun org-starter-load-all-files-in-path ()
1703 | "Load all org files in `org-starter-path' into Emacs.
1704 |
1705 | This can be convenient in some situations where you want ensure that all org
1706 | files are in buffers.
1707 |
1708 | `org-starter-get-all-files-in-path' is used to get a list of org files."
1709 | (interactive)
1710 | (mapc #'org-starter--load-file (org-starter-get-all-files-in-path)))
1711 |
1712 | ;;;; Loading external config files
1713 |
1714 | ;;;###autoload
1715 | (defun org-starter-load-config-files ()
1716 | "Load config files in `org-starter-path'."
1717 | (interactive)
1718 | (mapc #'load-file (org-starter--get-existing-config-files))
1719 | (setq org-starter-suppress-override-messages-once nil))
1720 |
1721 | (defun org-starter--get-existing-config-files (&optional dirs)
1722 | "Return a list of existing config files.
1723 |
1724 | DIRS is a list of directories to check.
1725 | If it is non-nil, search config files from the directories.
1726 | Otherwise, it searches from `org-starter-path'."
1727 | (org-starter--get-files-in-path org-starter-config-file-name dirs))
1728 |
1729 | (defun org-starter--get-files-in-path (filename &optional dirs)
1730 | "Return a list of files in the path with a particular file name.
1731 |
1732 | This function looks for files with FILENAME in directories. By
1733 | default, the directories are `org-starter-path', but you can also
1734 | specify DIRS.
1735 |
1736 | It returns only existing files."
1737 | (let ((dirs (or dirs org-starter-path)))
1738 | (->> (if org-directory
1739 | (cons org-directory
1740 | (cl-remove org-directory dirs :test #'file-equal-p))
1741 | (copy-sequence dirs))
1742 | (-map #'expand-file-name)
1743 | (funcall (-flip #'-difference)
1744 | (-map #'expand-file-name
1745 | org-starter-prevent-local-config-directories))
1746 | (--map (concat (file-name-as-directory it) filename))
1747 | (-filter #'file-exists-p))))
1748 |
1749 | ;; Export it as a utility function
1750 | ;;;###autoload
1751 | (defalias 'org-starter-get-files-in-path #'org-starter--get-files-in-path)
1752 |
1753 | ;;;###autoload
1754 | (defun org-starter-find-config-file ()
1755 | "Visit an existing config file for org-starter."
1756 | (interactive)
1757 | (find-file (completing-read "Config file: "
1758 | (org-starter--get-existing-config-files)
1759 | nil t)))
1760 |
1761 | ;;;; UI utilities
1762 |
1763 | (defun org-starter--display-options (header items)
1764 | "Display items possibly in a child frame.
1765 |
1766 | HEADER is a line inserted at the beginning of the string,
1767 | ITEMS is a list of strings."
1768 | (if (and org-starter-use-child-frame
1769 | (or (require 'posframe nil t)
1770 | (progn
1771 | (message "org-starter: posframe is not installed, so falling back to the echo area")
1772 | nil))
1773 | ;; Child frames don't work well by default in EXWM,
1774 | ;; but it is up to the user to work around this issue.
1775 | ;; (not (derived-mode-p 'exwm-mode))
1776 | (or (posframe-workable-p)
1777 | (progn
1778 | (message "org-starter: posframe does not work here, so falling back to the echo area")
1779 | nil)))
1780 | (let ((lines (cons header
1781 | (org-starter--format-table
1782 | items
1783 | (min 80 (frame-width))))))
1784 | (posframe-show org-starter-message-buffer
1785 | :internal-border-width org-starter-child-frame-border-width
1786 | :internal-border-color org-starter-child-frame-border-color
1787 | :foreground-color org-starter-child-frame-foreground-color
1788 | :background-color org-starter-child-frame-background-color
1789 | :override-parameters org-starter-child-frame-override-parameters
1790 | :string (string-join lines "\n")
1791 | :height (1+ (length lines))
1792 | :width (-max (-map #'length lines))
1793 | :poshandler org-starter-child-frame-poshandler)
1794 | (add-hook 'pre-command-hook #'org-starter--delete-message-frame))
1795 | (message (string-join
1796 | (cons header
1797 | (org-starter--format-table items
1798 | (frame-width)))
1799 | "\n"))))
1800 |
1801 | (defun org-starter--format-table (cells frame-width)
1802 | "Format CELLS in columns in FRAME-WIDTH in total."
1803 | (let* ((cell-width (min 24 (-max (-map #'length cells))))
1804 | (cols (/ frame-width (1+ cell-width)))
1805 | (rows (-partition-all cols cells)))
1806 | (-map (lambda (cells)
1807 | (mapconcat (lambda (content)
1808 | (if (> (length content) cell-width)
1809 | (substring content 0 cell-width)
1810 | (concat content
1811 | (make-string (- cell-width (length content))
1812 | 32))))
1813 | cells " "))
1814 | rows)))
1815 |
1816 | (defun org-starter--delete-message-frame ()
1817 | "Delete the child frame for messages."
1818 | (posframe-delete-frame org-starter-message-buffer)
1819 | (remove-hook 'pre-command-hook #'org-starter--delete-message-frame))
1820 |
1821 | (provide 'org-starter)
1822 | ;;;; Load external configuration files
1823 | (when org-starter-load-config-files
1824 | ;; If Emacs has been started. load the files immediately.
1825 | (if after-init-time
1826 | (org-starter-load-config-files)
1827 | ;; Otherwise, load them after startup.
1828 | (setq org-starter-suppress-override-messages-once t)
1829 | (add-hook 'after-init-hook #'org-starter-load-config-files)))
1830 | ;;; org-starter.el ends here
1831 |
--------------------------------------------------------------------------------
/screenshots/org-starter-refile-by-key.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/akirak/org-starter/cd9c5c0402de941299d1c8901f26a8f24d755022/screenshots/org-starter-refile-by-key.png
--------------------------------------------------------------------------------