forked from thomasf/solarized-css
-
Notifications
You must be signed in to change notification settings - Fork 0
/
org-hacks.html
4852 lines (4359 loc) · 244 KB
/
org-hacks.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Org ad hoc code, quick hacks and workarounds</title>
<!-- 2013-08-08 tor 11:56 -->
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<meta name="generator" content="Org-mode"/>
<meta name="author" content="Worg people"/>
<style type="text/css">
<!--/*--><![CDATA[/*><!--*/
.title { text-align: center; }
.todo { font-family: monospace; color: red; }
.done { color: green; }
.tag { background-color: #eee; font-family: monospace;
padding: 2px; font-size: 80%; font-weight: normal; }
.timestamp { color: #bebebe; }
.timestamp-kwd { color: #5f9ea0; }
.right { margin-left: auto; margin-right: 0px; text-align: right; }
.left { margin-left: 0px; margin-right: auto; text-align: left; }
.center { margin-left: auto; margin-right: auto; text-align: center; }
.underline { text-decoration: underline; }
#postamble p, #preamble p { font-size: 90%; margin: .2em; }
p.verse { margin-left: 3%; }
pre {
border: 1px solid #ccc;
box-shadow: 3px 3px 3px #eee;
padding: 8pt;
font-family: monospace;
overflow: auto;
margin: 1.2em;
}
pre.src {
position: relative;
overflow: visible;
padding-top: 1.2em;
}
pre.src:before {
display: none;
position: absolute;
background-color: white;
top: -10px;
right: 10px;
padding: 3px;
border: 1px solid black;
}
pre.src:hover:before { display: inline;}
pre.src-sh:before { content: 'sh'; }
pre.src-bash:before { content: 'sh'; }
pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
pre.src-R:before { content: 'R'; }
pre.src-perl:before { content: 'Perl'; }
pre.src-java:before { content: 'Java'; }
pre.src-sql:before { content: 'SQL'; }
table { border-collapse:collapse; }
td, th { vertical-align:top; }
th.right { text-align: center; }
th.left { text-align: center; }
th.center { text-align: center; }
td.right { text-align: right; }
td.left { text-align: left; }
td.center { text-align: center; }
dt { font-weight: bold; }
.footpara:nth-child(2) { display: inline; }
.footpara { display: block; }
.footdef { margin-bottom: 1em; }
.figure { padding: 1em; }
.figure p { text-align: center; }
.inlinetask {
padding: 10px;
border: 2px solid gray;
margin: 10px;
background: #ffffcc;
}
#org-div-home-and-up
{ text-align: right; font-size: 70%; white-space: nowrap; }
textarea { overflow-x: auto; }
.linenr { font-size: smaller }
.code-highlighted { background-color: #ffff00; }
.org-info-js_info-navigation { border-style: none; }
#org-info-js_console-label
{ font-size: 10px; font-weight: bold; white-space: nowrap; }
.org-info-js_search-highlight
{ background-color: #ffff00; color: #000000; font-weight: bold; }
/*]]>*/-->
</style>
<link rel="stylesheet" type="text/css" href="http://thomasf.github.io/solarized-css/solarized-light.min.css" />
<script type="text/javascript">
/*
@licstart The following is the entire license notice for the
JavaScript code in this tag.
Copyright (C) 2012 Free Software Foundation, Inc.
The JavaScript code in this tag is free software: you can
redistribute it and/or modify it under the terms of the GNU
General Public License (GNU GPL) as published by the Free Software
Foundation, either version 3 of the License, or (at your option)
any later version. The code is distributed WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
As additional permission under GNU GPL version 3 section 7, you
may distribute non-source (e.g., minimized or compacted) forms of
that code without the copy of the GNU GPL normally required by
section 4, provided you include this license notice and a URL
through which recipients can access the Corresponding Source.
@licend The above is the entire license notice
for the JavaScript code in this tag.
*/
<!--/*--><![CDATA[/*><!--*/
function CodeHighlightOn(elem, id)
{
var target = document.getElementById(id);
if(null != target) {
elem.cacheClassElem = elem.className;
elem.cacheClassTarget = target.className;
target.className = "code-highlighted";
elem.className = "code-highlighted";
}
}
function CodeHighlightOff(elem, id)
{
var target = document.getElementById(id);
if(elem.cacheClassElem)
elem.className = elem.cacheClassElem;
if(elem.cacheClassTarget)
target.className = elem.cacheClassTarget;
}
/*]]>*///-->
</script>
</head>
<body>
<div id="content">
<h1 class="title">Org ad hoc code, quick hacks and workarounds</h1>
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#sec-1">Hacking Org: Working within Org-mode.</a>
<ul>
<li><a href="#sec-1-1">Org Agenda</a>
<ul>
<li><a href="#sec-1-1-1">Picking up a random task in the global TODO list</a></li>
</ul>
</li>
<li><a href="#sec-1-2">Building and Managing Org</a>
<ul>
<li><a href="#compiling-org-without-make">Generating autoloads and Compiling Org without make</a></li>
<li><a href="#sec-1-2-2">Reload Org</a></li>
<li><a href="#check-old-link-escapes">Check for possibly problematic old link escapes</a></li>
</ul>
</li>
<li><a href="#sec-1-3">Structure Movement and Editing</a>
<ul>
<li><a href="#sec-1-3-1">Show next/prev heading tidily</a></li>
<li><a href="#sec-1-3-2">Promote all items in subtree</a></li>
<li><a href="#heading-to-link">Turn a heading into an Org link</a></li>
<li><a href="#sec-1-3-4">Using M-up and M-down to transpose paragraphs</a></li>
<li><a href="#sec-1-3-5">Changelog support for org headers</a></li>
<li><a href="#sec-1-3-6">Different org-cycle-level behavior</a></li>
<li><a href="#sec-1-3-7">Count words in an Org buffer</a></li>
<li><a href="#sec-1-3-8">Check for misplaced SCHEDULED and DEADLINE cookies</a></li>
<li><a href="#sec-1-3-9">Sorting list by checkbox type</a></li>
</ul>
</li>
<li><a href="#sec-1-4">Org Table</a>
<ul>
<li><a href="#sec-1-4-1">Align all tables in a file</a></li>
<li><a href="#transpose-table">Transpose table</a></li>
<li><a href="#sec-1-4-3">Manipulate hours/minutes/seconds in table formulas</a></li>
<li><a href="#sec-1-4-4">Dates computation</a></li>
<li><a href="#sec-1-4-5">Hex computation</a></li>
<li><a href="#field-coordinates-in-formulas">Field coordinates in formulas (<code>@#</code> and <code>$#</code>)</a></li>
<li><a href="#column-sequence-in-row">Change the column sequence in one row only</a></li>
</ul>
</li>
<li><a href="#sec-1-5">Capture and Remember</a>
<ul>
<li><a href="#sec-1-5-1">Customize the size of the frame for remember</a></li>
</ul>
</li>
<li><a href="#sec-1-6">Handling Links</a>
<ul>
<li><a href="#sec-1-6-1">Turn a heading into an org link</a></li>
<li><a href="#sec-1-6-2">Quickaccess to the link part of hyperlinks</a></li>
<li><a href="#sec-1-6-3">Insert link with HTML title as default description</a></li>
</ul>
</li>
<li><a href="#sec-1-7">Archiving Content in Org-Mode</a>
<ul>
<li><a href="#sec-1-7-1">Preserve top level headings when archiving to a file</a></li>
<li><a href="#sec-1-7-2">Archive in a date tree</a></li>
<li><a href="#sec-1-7-3">Add inherited tags to archived entries</a></li>
</ul>
</li>
<li><a href="#sec-1-8">Using and Managing Org-Metadata</a>
<ul>
<li><a href="#sec-1-8-1">Remove redundant tags of headlines</a></li>
<li><a href="#sec-1-8-2">Remove empty property drawers</a></li>
<li><a href="#sec-1-8-3">Group task list by a property</a></li>
<li><a href="#sec-1-8-4">A way to tag a task so that when clocking-out user is prompted to take a note.</a></li>
<li><a href="#sec-1-8-5">Dynamically adjust tag position</a></li>
<li><a href="#sec-1-8-6">Use an "attach" link type to open files without worrying about their location</a></li>
</ul>
</li>
<li><a href="#sec-1-9">Org Agenda and Task Management</a>
<ul>
<li><a href="#sec-1-9-1">Make it easier to set org-agenda-files from multiple directories</a></li>
<li><a href="#set-agenda-files-by-filetag">Restrict org-agenda-files by filetag</a></li>
<li><a href="#sec-1-9-3">Highlight the agenda line under cursor</a></li>
<li><a href="#sec-1-9-4">Split frame horizontally for agenda</a></li>
<li><a href="#sec-1-9-5">Automatically add an appointment when clocking in a task</a></li>
<li><a href="#sec-1-9-6">Using external programs for appointments reminders</a></li>
<li><a href="#sec-1-9-7">Remove from agenda time grid lines that are in an appointment</a></li>
<li><a href="#sec-1-9-8">Disable version control for Org mode agenda files</a></li>
<li><a href="#sec-1-9-9">Easy customization of TODO colors</a></li>
<li><a href="#sec-1-9-10">Add an effort estimate on the fly when clocking in</a></li>
<li><a href="#sec-1-9-11">Use idle timer for automatic agenda views</a></li>
<li><a href="#sec-1-9-12">Refresh the agenda view regularly</a></li>
<li><a href="#sec-1-9-13">Reschedule agenda items to today with a single command</a></li>
<li><a href="#sec-1-9-14">Mark subtree DONE along with all subheadings</a></li>
<li><a href="#mark-done-when-all-checkboxes-checked">Mark heading done when all checkboxes are checked.</a></li>
<li><a href="#links-to-agenda-views">Links to custom agenda views</a></li>
</ul>
</li>
<li><a href="#sec-1-10">Exporting org files</a>
<ul>
<li><a href="#sec-1-10-1">Export Org to Org and handle includes.</a></li>
<li><a href="#latex-command-for-floats">Specifying LaTeX commands to floating environments</a></li>
<li><a href="#sec-1-10-3">Styling code sections with CSS</a></li>
</ul>
</li>
<li><a href="#sec-1-11">Babel</a>
<ul>
<li><a href="#sec-1-11-1">How do I preview LaTeX fragments when in a LaTeX source block?</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#sec-2">Hacking Org: Working with Org-mode and other Emacs Packages.</a>
<ul>
<li><a href="#sec-2-1">org-remember-anything</a></li>
<li><a href="#sec-2-2">Org-mode and saveplace.el</a></li>
<li><a href="#sec-2-3">Using ido-mode for org-refile (and archiving via refile)</a></li>
<li><a href="#sec-2-4">Using ido-completing-read to find attachments</a></li>
<li><a href="#sec-2-5">Link to Gnus messages by Message-Id</a></li>
<li><a href="#sec-2-6">Store link to a message when sending in Gnus</a></li>
<li><a href="#sec-2-7">Send html messages and attachments with Wanderlust</a>
<ul>
<li><a href="#sec-2-7-1">Send HTML message</a></li>
<li><a href="#sec-2-7-2">Attach HTML of region or subtree</a></li>
<li><a href="#sec-2-7-3">Adopting for Gnus</a></li>
</ul>
</li>
<li><a href="#sec-2-8">Add sunrise/sunset times to the agenda.</a></li>
<li><a href="#sec-2-9">Add lunar phases to the agenda.</a></li>
</ul>
</li>
<li><a href="#sec-3">Lunar phase</a>
<ul>
<li><a href="#sec-3-1">Export BBDB contacts to org-contacts.el</a></li>
<li><a href="#sec-3-2">Calculating date differences - how to write a simple elisp function</a></li>
<li><a href="#sec-3-3">ibuffer and org files</a></li>
<li><a href="#sec-3-4">Enable org-mode links in other modes</a></li>
<li><a href="#sec-3-5">poporg.el: edit comments in org-mode</a></li>
<li><a href="#sec-3-6">Convert a .csv file to an Org-mode table</a></li>
</ul>
</li>
<li><a href="#sec-4">Hacking Org: Working with Org-mode and External Programs.</a>
<ul>
<li><a href="#sec-4-1">Use Org-mode with Screen [Andrew Hyatt]</a></li>
<li><a href="#org-agenda-appt-zenity">Org Agenda + Appt + Zenity</a></li>
<li><a href="#sec-4-3">Org and appointment notifications on Mac OS 10.8</a></li>
<li><a href="#sec-4-4">Org-Mode + gnome-osd</a></li>
<li><a href="#sec-4-5">txt2org convert text data to org-mode tables</a></li>
<li><a href="#sec-4-6">remind2org</a></li>
<li><a href="#sec-4-7">Useful webjumps for conkeror</a></li>
<li><a href="#sec-4-8">Use MathJax for HTML export without requiring JavaScript</a></li>
<li><a href="#sec-4-9">Search Org files using lgrep</a></li>
<li><a href="#sec-4-10">Automatic screenshot insertion</a></li>
<li><a href="#sec-4-11">Capture invitations/appointments from MS Exchange emails</a></li>
<li><a href="#sec-4-12">Audio/video file playback within org mode</a></li>
<li><a href="#sec-4-13">Under X11 Keep a window with the current agenda items at all time</a></li>
<li><a href="#sec-4-14">Script (thru procmail) to output emails to an Org file</a></li>
<li><a href="#fileconversion">Save File With Different Format for Headings (fileconversion)</a>
<ul>
<li><a href="#hidestarsfile">Headings Without Leading Stars (hidestarsfile and nbspstarsfile)</a></li>
<li><a href="#markdownstarsfile">Headings in Markdown Format (markdownstarsfile)</a></li>
<li><a href="#fileconversion-code">emacs-lisp code</a></li>
</ul>
</li>
<li><a href="#sec-4-16">Meaningful diff for org files in a git repository</a></li>
<li><a href="#sec-4-17">Opening devonthink links</a></li>
</ul>
</li>
<li><a href="#sec-5">Musings</a>
<ul>
<li><a href="#sec-5-1">Cooking? Brewing?</a></li>
</ul>
</li>
</ul>
</div>
</div>
<p>
<a href="index.html">{Back to Worg's index}</a>
</p>
<p>
This page is for ad hoc bits of code. Feel free to add quick hacks and
workaround. Go crazy.
</p>
<div id="outline-container-sec-1" class="outline-2">
<h2 id="sec-1">Hacking Org: Working within Org-mode.</h2>
<div class="outline-text-2" id="text-1">
</div><div id="outline-container-sec-1-1" class="outline-3">
<h3 id="sec-1-1">Org Agenda</h3>
<div class="outline-text-3" id="text-1-1">
</div><div id="outline-container-sec-1-1-1" class="outline-4">
<h4 id="sec-1-1-1">Picking up a random task in the global TODO list</h4>
<div class="outline-text-4" id="text-1-1-1">
<p>
Tony day <a href="http://mid.gmane.org/m2zk19l1me.fsf%2540gmail.com">shared</a> <a href="https://gist.github.com/4343164">this gist</a> to pick up a
random task.
</p>
</div>
</div>
</div>
<div id="outline-container-sec-1-2" class="outline-3">
<h3 id="sec-1-2">Building and Managing Org</h3>
<div class="outline-text-3" id="text-1-2">
</div><div id="outline-container-compiling-org-without-make" class="outline-4">
<h4 id="compiling-org-without-make"><a id="sec-1-2-1" name="sec-1-2-1"></a>Generating autoloads and Compiling Org without make</h4>
<div class="outline-text-4" id="text-compiling-org-without-make">
<p>
Compilation is optional, but you <span class="underline">must</span> update the autoloads file
each time you update org, even when you run org uncompiled!
</p>
<p>
Starting with Org 7.9 you'll find functions for creating the
autoload files and do byte-compilation in <code>mk/org-fixup.el</code>. When
you execute the commands below, your current directory must be where
org has been unpacked into, in other words the file <code>README</code> should
be found in your current directory and the directories <code>lisp</code> and
<code>etc</code> should be subdirectories of it. The command <code>emacs</code> should be
found in your <code>PATH</code> and start the Emacs version you are using. To
make just the autoloads file do:
</p>
<pre class="example">
emacs -batch -Q -L lisp -l ../mk/org-fixup -f org-make-autoloads
</pre>
<p>
To make the autoloads file and byte-compile org:
</p>
<pre class="example">
emacs -batch -Q -L lisp -l ../mk/org-fixup -f org-make-autoloads-compile
</pre>
<p>
To make the autoloads file and byte-compile all of org again:
</p>
<pre class="example">
emacs -batch -Q -L lisp -l ../mk/org-fixup -f org-make-autoloads-compile-force
</pre>
<p>
If you are not using Git, you'll have to make fake version strings
first if <code>org-version.el</code> is not already available (if it is, you
could also edit the version strings there).
</p>
<pre class="example">
emacs -batch -Q -L lisp -l ../mk/org-fixup \
--eval '(let ((org-fake-release "7.9.1")(org-fake-git-version "7.9.1-fake"))\
(org-make-autoloads))'
</pre>
<p>
The above assumes a
POSIX shell for its quoting. Windows <code>CMD.exe</code> has quite different
quoting rules and this won't work, so your other option is to start
Emacs like this
</p>
<pre class="example">
emacs -Q -L lisp -l ../mk/org-fixup
</pre>
<p>
then paste the following into the <code>*scratch*</code> buffer
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #859900;">let</span> ((org-fake-release <span style="color: #2aa198;">"7.9.1"</span>)
(org-fake-git-version <span style="color: #2aa198;">"7.9.1-fake"</span>))
(org-make-autoloads))
</pre>
</div>
<p>
position the cursor after the closing paren and press <code>C-j</code> or <code>C-x
C-e</code> to evaluate the form. Of course you can replace
<code>org-make-autoloads</code> with <code>org-make-autoloads-compile</code> or even
<code>org-make-autoloads-compile-force</code> if you wish with both variants.
</p>
<p>
For <b>older org versions only</b> (that do not yet have
<code>mk/org-fixup.el</code>), you can use the definitions below. To use
this function, adjust the variables <code>my/org-lisp-directory</code> and
<code>my/org-compile-sources</code> to suit your needs. If you have
byte-compiled org, but want to run org uncompiled again, just remove
all <code>*.elc</code> files in the <code>lisp/</code> directory, set
<code>my/org-compile-sources</code> to <code>nil</code>.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #859900;">defvar</span> <span style="color: #268bd2;">my/org-lisp-directory</span> <span style="color: #2aa198;">"~/.emacs.d/org/lisp/"</span>
<span style="color: #2aa198; font-style: italic;">"Directory where your org-mode files live."</span>)
(<span style="color: #859900;">defvar</span> <span style="color: #268bd2;">my/org-compile-sources</span> t
<span style="color: #2aa198; font-style: italic;">"If `</span><span style="color: #2aa198; font-weight: bold; font-style: italic;">nil</span><span style="color: #2aa198; font-style: italic;">', never compile org-sources. `</span><span style="color: #2aa198; font-weight: bold; font-style: italic;">my/compile-org</span><span style="color: #2aa198; font-style: italic;">' will only create</span>
<span style="color: #2aa198; font-style: italic;">the autoloads file `</span><span style="color: #2aa198; font-weight: bold; font-style: italic;">org-loaddefs.el</span><span style="color: #2aa198; font-style: italic;">' then. If `t', compile the sources, too."</span>)
<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">Customize: (must end with a slash!)</span>
(setq my/org-lisp-directory <span style="color: #2aa198;">"~/.emacs.d/org/lisp/"</span>)
<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">Customize:</span>
(setq my/org-compile-sources t)
(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">my/compile-org</span>(<span style="color: #b58900;">&optional</span> directory)
<span style="color: #2aa198; font-style: italic;">"Generate autoloads file org-loaddefs.el. Optionally compile</span>
<span style="color: #2aa198; font-style: italic;"> all *.el files that come with org-mode."</span>
(interactive)
(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">my/compile-org</span>()
<span style="color: #2aa198; font-style: italic;">"Generate autoloads file org-loaddefs.el. Optionally compile</span>
<span style="color: #2aa198; font-style: italic;"> all *.el files that come with org-mode."</span>
(interactive)
(<span style="color: #859900;">let</span> ((dirlisp (file-name-directory my/org-lisp-directory)))
(add-to-list 'load-path dirlisp)
(<span style="color: #859900;">require</span> '<span style="color: #268bd2; font-weight: bold;">autoload</span>)
(<span style="color: #859900;">let</span> ((generated-autoload-file (concat dirlisp <span style="color: #2aa198;">"org-loaddefs.el"</span>)))
<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">create the org-loaddefs file</span>
(update-directory-autoloads dirlisp)
(<span style="color: #859900;">when</span> my/org-compile-sources
<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">optionally byte-compile</span>
(byte-recompile-directory dirlisp 0 'force)))))
</pre>
</div>
</div>
</div>
<div id="outline-container-sec-1-2-2" class="outline-4">
<h4 id="sec-1-2-2">Reload Org</h4>
<div class="outline-text-4" id="text-1-2-2">
<p>
As of Org version 6.23b (released Sunday Feb 22, 2009) there is a new
function to reload org files.
</p>
<p>
Normally you want to use the compiled files since they are faster.
If you update your org files you can easily reload them with
</p>
<pre class="example">
M-x org-reload
</pre>
<p>
If you run into a bug and want to generate a useful backtrace you can
reload the source files instead of the compiled files with
</p>
<pre class="example">
C-u M-x org-reload
</pre>
<p>
and turn on the "Enter Debugger On Error" option. Redo the action
that generates the error and cut and paste the resulting backtrace.
To switch back to the compiled version just reload again with
</p>
<pre class="example">
M-x org-reload
</pre>
</div>
</div>
<div id="outline-container-check-old-link-escapes" class="outline-4">
<h4 id="check-old-link-escapes"><a id="sec-1-2-3" name="sec-1-2-3"></a>Check for possibly problematic old link escapes</h4>
<div class="outline-text-4" id="text-check-old-link-escapes">
<p>
Starting with version 7.5 Org uses <a href="http://en.wikipedia.org/wiki/Percent-encoding">percent escaping</a> more consistently
and with a modified algorithm to determine which characters to escape
and how.
</p>
<p>
As a side effect this modified behaviour might break existing links if
they contain a sequence of characters that look like a percent escape
(e.g. <code>[0-9A-Fa-f]{2}</code>) but are in fact not a percent escape.
</p>
<p>
The function below can be used to perform a preliminary check for such
links in an Org mode file. It will run through all links in the file
and issue a warning if it finds a percent escape sequence which is not
in old Org's list of known percent escapes.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">dmaus/org-check-percent-escapes</span> ()
<span style="color: #2aa198; font-style: italic;">"*Check buffer for possibly problematic old link escapes."</span>
(interactive)
(<span style="color: #859900;">when</span> (eq major-mode 'org-mode)
(<span style="color: #859900;">let</span> ((old-escapes '(<span style="color: #2aa198;">"%20"</span> <span style="color: #2aa198;">"%5B"</span> <span style="color: #2aa198;">"%5D"</span> <span style="color: #2aa198;">"%E0"</span> <span style="color: #2aa198;">"%E2"</span> <span style="color: #2aa198;">"%E7"</span> <span style="color: #2aa198;">"%E8"</span> <span style="color: #2aa198;">"%E9"</span>
<span style="color: #2aa198;">"%EA"</span> <span style="color: #2aa198;">"%EE"</span> <span style="color: #2aa198;">"%F4"</span> <span style="color: #2aa198;">"%F9"</span> <span style="color: #2aa198;">"%FB"</span> <span style="color: #2aa198;">"%3B"</span> <span style="color: #2aa198;">"%3D"</span> <span style="color: #2aa198;">"%2B"</span>)))
(<span style="color: #859900;">unless</span> (boundp 'warning-suppress-types)
(setq warning-suppress-types <span style="color: #b58900;">nil</span>))
(widen)
(show-all)
(goto-char (point-min))
(<span style="color: #859900;">while</span> (re-search-forward org-any-link-re <span style="color: #b58900;">nil</span> t)
(<span style="color: #859900;">let</span> ((end (match-end 0)))
(goto-char (match-beginning 0))
(<span style="color: #859900;">while</span> (re-search-forward <span style="color: #2aa198;">"%[0-9a-zA-Z]\\{2\\}"</span> end t)
(<span style="color: #859900;">let</span> ((escape (match-string-no-properties 0)))
(<span style="color: #859900;">unless</span> (member (upcase escape) old-escapes)
(<span style="color: #cb4b16; font-weight: bold; text-decoration: underline;">warn</span> <span style="color: #2aa198;">"Found unknown percent escape sequence %s at buffer %s, position %d"</span>
escape
(buffer-name)
(<span style="color: #b58900;">-</span> (point) 3)))))
(goto-char end))))))
</pre>
</div>
</div>
</div>
</div>
<div id="outline-container-sec-1-3" class="outline-3">
<h3 id="sec-1-3">Structure Movement and Editing</h3>
<div class="outline-text-3" id="text-1-3">
</div><div id="outline-container-sec-1-3-1" class="outline-4">
<h4 id="sec-1-3-1">Show next/prev heading tidily</h4>
<div class="outline-text-4" id="text-1-3-1">
<ul class="org-ul">
<li>Dan Davison
These close the current heading and open the next/previous heading.
</li>
</ul>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">ded/org-show-next-heading-tidily</span> ()
<span style="color: #2aa198; font-style: italic;">"Show next entry, keeping other entries closed."</span>
(<span style="color: #859900;">if</span> (<span style="color: #859900;">save-excursion</span> (end-of-line) (outline-invisible-p))
(<span style="color: #859900;">progn</span> (org-show-entry) (show-children))
(outline-next-heading)
(<span style="color: #859900;">unless</span> (<span style="color: #b58900;">and</span> (bolp) (org-on-heading-p))
(org-up-heading-safe)
(hide-subtree)
(<span style="color: #cb4b16; font-weight: bold; text-decoration: underline;">error</span> <span style="color: #2aa198;">"Boundary reached"</span>))
(org-overview)
(org-reveal t)
(org-show-entry)
(show-children)))
(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">ded/org-show-previous-heading-tidily</span> ()
<span style="color: #2aa198; font-style: italic;">"Show previous entry, keeping other entries closed."</span>
(<span style="color: #859900;">let</span> ((pos (point)))
(outline-previous-heading)
(<span style="color: #859900;">unless</span> (<span style="color: #b58900;">and</span> (<span style="color: #b58900;"><</span> (point) pos) (bolp) (org-on-heading-p))
(goto-char pos)
(hide-subtree)
(<span style="color: #cb4b16; font-weight: bold; text-decoration: underline;">error</span> <span style="color: #2aa198;">"Boundary reached"</span>))
(org-overview)
(org-reveal t)
(org-show-entry)
(show-children)))
(setq org-use-speed-commands t)
(add-to-list 'org-speed-commands-user
'(<span style="color: #2aa198;">"n"</span> ded/org-show-next-heading-tidily))
(add-to-list 'org-speed-commands-user
'(<span style="color: #2aa198;">"p"</span> ded/org-show-previous-heading-tidily))
</pre>
</div>
</div>
</div>
<div id="outline-container-sec-1-3-2" class="outline-4">
<h4 id="sec-1-3-2">Promote all items in subtree</h4>
<div class="outline-text-4" id="text-1-3-2">
<ul class="org-ul">
<li>Matt Lundin
</li>
</ul>
<p>
This function will promote all items in a subtree. Since I use
subtrees primarily to organize projects, the function is somewhat
unimaginatively called my-org-un-project:
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">my-org-un-project</span> ()
(interactive)
(org-map-entries 'org-do-promote <span style="color: #2aa198;">"LEVEL>1"</span> 'tree)
(org-cycle t))
</pre>
</div>
</div>
</div>
<div id="outline-container-heading-to-link" class="outline-4">
<h4 id="heading-to-link"><a id="sec-1-3-3" name="sec-1-3-3"></a>Turn a heading into an Org link</h4>
<div class="outline-text-4" id="text-heading-to-link">
<p>
From David Maus:
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">dmj:turn-headline-into-org-mode-link</span> ()
<span style="color: #2aa198; font-style: italic;">"Replace word at point by an Org mode link."</span>
(interactive)
(<span style="color: #859900;">when</span> (org-at-heading-p)
(<span style="color: #859900;">let</span> ((hl-text (nth 4 (org-heading-components))))
(<span style="color: #859900;">unless</span> (<span style="color: #b58900;">or</span> (null hl-text)
(org-string-match-p <span style="color: #2aa198;">"^[ \t]*:[</span><span style="color: #2aa198; font-weight: bold;">^</span><span style="color: #2aa198;">:]+:$"</span> hl-text))
(beginning-of-line)
(search-forward hl-text (point-at-eol))
(replace-string
hl-text
(format <span style="color: #2aa198;">"[[file:%s.org][%s]]"</span>
(org-link-escape hl-text)
(org-link-escape hl-text '((?\] . <span style="color: #2aa198;">"%5D"</span>) (?\[ . <span style="color: #2aa198;">"%5B"</span>))))
<span style="color: #b58900;">nil</span> (<span style="color: #b58900;">-</span> (point) (length hl-text)) (point))))))
</pre>
</div>
</div>
</div>
<div id="outline-container-sec-1-3-4" class="outline-4">
<h4 id="sec-1-3-4">Using M-up and M-down to transpose paragraphs</h4>
<div class="outline-text-4" id="text-1-3-4">
<p>
From Paul Sexton: By default, if used within ordinary paragraphs in
org mode, <code>M-up</code> and <code>M-down</code> transpose <b>lines</b> (not sentences). The
following code makes these keys transpose paragraphs, keeping the
point at the start of the moved paragraph. Behavior in tables and
headings is unaffected. It would be easy to modify this to transpose
sentences.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">org-transpose-paragraphs</span> (arg)
(interactive)
(<span style="color: #859900;">when</span> (<span style="color: #b58900;">and</span> (<span style="color: #b58900;">not </span>(<span style="color: #b58900;">or</span> (org-at-table-p) (org-on-heading-p) (org-at-item-p)))
(thing-at-point 'sentence))
(transpose-paragraphs arg)
(backward-paragraph)
(re-search-forward <span style="color: #2aa198;">"[[:graph:]]"</span>)
(goto-char (match-beginning 0))
t))
(add-to-list 'org-metaup-hook
(<span style="color: #b58900;">lambda</span> () (interactive) (org-transpose-paragraphs -1)))
(add-to-list 'org-metadown-hook
(<span style="color: #b58900;">lambda</span> () (interactive) (org-transpose-paragraphs 1)))
</pre>
</div>
</div>
</div>
<div id="outline-container-sec-1-3-5" class="outline-4">
<h4 id="sec-1-3-5">Changelog support for org headers</h4>
<div class="outline-text-4" id="text-1-3-5">
<p>
– James TD Smith
</p>
<p>
Put the following in your <code>.emacs</code>, and <code>C-x 4 a</code> and other functions which
use <code>add-log-current-defun</code> like <code>magit-add-log</code> will pick up the nearest org
headline as the "current function" if you add a changelog entry from an org
buffer.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">org-log-current-defun</span> ()
(<span style="color: #859900;">save-excursion</span>
(org-back-to-heading)
(<span style="color: #859900;">if</span> (looking-at org-complex-heading-regexp)
(match-string 4))))
(add-hook 'org-mode-hook
(<span style="color: #b58900;">lambda</span> ()
(make-variable-buffer-local 'add-log-current-defun-function)
(setq add-log-current-defun-function 'org-log-current-defun)))
</pre>
</div>
</div>
</div>
<div id="outline-container-sec-1-3-6" class="outline-4">
<h4 id="sec-1-3-6">Different org-cycle-level behavior</h4>
<div class="outline-text-4" id="text-1-3-6">
<p>
– Ryan Thompson
</p>
<p>
In recent org versions, when your point (cursor) is at the end of an
empty header line (like after you first created the header), the TAB
key (<code>org-cycle</code>) has a special behavior: it cycles the headline through
all possible levels. However, I did not like the way it determined
"all possible levels," so I rewrote the whole function, along with a
couple of supporting functions.
</p>
<p>
The original function's definition of "all possible levels" was "every
level from 1 to one more than the initial level of the current
headline before you started cycling." My new definition is "every
level from 1 to one more than the previous headline's level." So, if
you have a headline at level 4 and you use ALT+RET to make a new
headline below it, it will cycle between levels 1 and 5, inclusive.
</p>
<p>
The main advantage of my custom <code>org-cycle-level</code> function is that it
is stateless: the next level in the cycle is determined entirely by
the contents of the buffer, and not what command you executed last.
This makes it more predictable, I hope.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #859900;">require</span> '<span style="color: #268bd2; font-weight: bold;">cl</span>)
(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">org-point-at-end-of-empty-headline</span> ()
<span style="color: #2aa198; font-style: italic;">"If point is at the end of an empty headline, return t, else nil."</span>
(<span style="color: #b58900;">and</span> (looking-at <span style="color: #2aa198;">"[ \t]*$"</span>)
(<span style="color: #859900;">save-excursion</span>
(beginning-of-line 1)
(looking-at (concat <span style="color: #2aa198;">"^</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">(</span><span style="color: #2aa198;">\\*+</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">)</span><span style="color: #2aa198;">[ \t]+</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">(</span><span style="color: #2aa198;">"</span> org-todo-regexp <span style="color: #2aa198;">"</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">)</span><span style="color: #2aa198;">?[ \t]*"</span>)))))
(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">org-level-increment</span> ()
<span style="color: #2aa198; font-style: italic;">"Return the number of stars that will be added or removed at a</span>
<span style="color: #2aa198; font-style: italic;">time to headlines when structure editing, based on the value of</span>
<span style="color: #2aa198; font-style: italic;">`</span><span style="color: #2aa198; font-weight: bold; font-style: italic;">org-odd-levels-only</span><span style="color: #2aa198; font-style: italic;">'."</span>
(<span style="color: #859900;">if</span> org-odd-levels-only 2 1))
(<span style="color: #859900;">defvar</span> <span style="color: #268bd2;">org-previous-line-level-cached</span> <span style="color: #b58900;">nil</span>)
(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">org-recalculate-previous-line-level</span> ()
<span style="color: #2aa198; font-style: italic;">"Same as `</span><span style="color: #2aa198; font-weight: bold; font-style: italic;">org-get-previous-line-level</span><span style="color: #2aa198; font-style: italic;">', but does not use cached</span>
<span style="color: #2aa198; font-style: italic;">value. It does *set* the cached value, though."</span>
(set 'org-previous-line-level-cached
(<span style="color: #859900;">let</span> ((current-level (org-current-level))
(prev-level (<span style="color: #859900;">when</span> (<span style="color: #b58900;">></span> (line-number-at-pos) 1)
(<span style="color: #859900;">save-excursion</span>
(previous-line)
(org-current-level)))))
(<span style="color: #859900;">cond</span> ((null current-level) <span style="color: #b58900;">nil</span>) <span style="color: #93a1a1; font-style: italic;">; </span><span style="color: #93a1a1;">Before first headline</span>
((null prev-level) 0) <span style="color: #93a1a1; font-style: italic;">; </span><span style="color: #93a1a1;">At first headline</span>
(prev-level)))))
(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">org-get-previous-line-level</span> ()
<span style="color: #2aa198; font-style: italic;">"Return the outline depth of the last headline before the</span>
<span style="color: #2aa198; font-style: italic;">current line. Returns 0 for the first headline in the buffer, and</span>
<span style="color: #2aa198; font-style: italic;">nil if before the first headline."</span>
<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">This calculation is quite expensive, with all the regex searching</span>
<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">and stuff. Since org-cycle-level won't change lines, we can reuse</span>
<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">the last value of this command.</span>
(<span style="color: #b58900;">or</span> (<span style="color: #b58900;">and</span> (eq last-command 'org-cycle-level)
org-previous-line-level-cached)
(org-recalculate-previous-line-level)))
(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">org-cycle-level</span> ()
(interactive)
(<span style="color: #859900;">let</span> ((org-adapt-indentation <span style="color: #b58900;">nil</span>))
(<span style="color: #859900;">when</span> (org-point-at-end-of-empty-headline)
(setq this-command 'org-cycle-level) <span style="color: #93a1a1; font-style: italic;">;</span><span style="color: #93a1a1;">Only needed for caching</span>
(<span style="color: #859900;">let</span> ((cur-level (org-current-level))
(prev-level (org-get-previous-line-level)))
(<span style="color: #859900;">cond</span>
<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">If first headline in file, promote to top-level.</span>
((= prev-level 0)
(<span style="color: #859900;">loop</span> repeat (/ (<span style="color: #b58900;">-</span> cur-level 1) (org-level-increment))
do (org-do-promote)))
<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">If same level as prev, demote one.</span>
((= prev-level cur-level)
(org-do-demote))
<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">If parent is top-level, promote to top level if not already.</span>
((= prev-level 1)
(<span style="color: #859900;">loop</span> repeat (/ (<span style="color: #b58900;">-</span> cur-level 1) (org-level-increment))
do (org-do-promote)))
<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">If top-level, return to prev-level.</span>
((= cur-level 1)
(<span style="color: #859900;">loop</span> repeat (/ (<span style="color: #b58900;">-</span> prev-level 1) (org-level-increment))
do (org-do-demote)))
<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">If less than prev-level, promote one.</span>
((<span style="color: #b58900;"><</span> cur-level prev-level)
(org-do-promote))
<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">If deeper than prev-level, promote until higher than</span>
<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">prev-level.</span>
((<span style="color: #b58900;">></span> cur-level prev-level)
(<span style="color: #859900;">loop</span> repeat (<span style="color: #b58900;">+</span> 1 (/ (<span style="color: #b58900;">-</span> cur-level prev-level) (org-level-increment)))
do (org-do-promote))))
t))))
</pre>
</div>
</div>
</div>
<div id="outline-container-sec-1-3-7" class="outline-4">
<h4 id="sec-1-3-7">Count words in an Org buffer</h4>
<div class="outline-text-4" id="text-1-3-7">
<p>
#FIXME: Does not fit too well under Structure. Any idea where to put it?
Paul Sexton <a href="http://article.gmane.org/gmane.emacs.orgmode/38014">posted</a> this function to count words in an Org buffer:
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">org-word-count</span> (beg end
<span style="color: #b58900;">&optional</span> count-latex-macro-args?
count-footnotes?)
<span style="color: #2aa198; font-style: italic;">"Report the number of words in the Org mode buffer or selected region.</span>
<span style="color: #2aa198; font-style: italic;">Ignores:</span>
<span style="color: #2aa198; font-style: italic;">- comments</span>
<span style="color: #2aa198; font-style: italic;">- tables</span>
<span style="color: #2aa198; font-style: italic;">- source code blocks (#+BEGIN_SRC ... #+END_SRC, and inline blocks)</span>
<span style="color: #2aa198; font-style: italic;">- hyperlinks (but does count words in hyperlink descriptions)</span>
<span style="color: #2aa198; font-style: italic;">- tags, priorities, and </span><span style="color: #cb4b16; background-color: #fdf6e3; font-style: italic;">TODO</span><span style="color: #2aa198; font-style: italic;"> keywords in headers</span>
<span style="color: #2aa198; font-style: italic;">- sections tagged as 'not for export'.</span>
<span style="color: #2aa198; font-style: italic;">The text of footnote definitions is ignored, unless the optional argument</span>
<span style="color: #2aa198; font-style: italic;">COUNT-FOOTNOTES? is non-nil.</span>
<span style="color: #2aa198; font-style: italic;">If the optional argument COUNT-LATEX-MACRO-ARGS? is non-nil, the word count</span>
<span style="color: #2aa198; font-style: italic;">includes LaTeX macro arguments (the material between {curly braces}).</span>
<span style="color: #2aa198; font-style: italic;">Otherwise, and by default, every LaTeX macro counts as 1 word regardless</span>
<span style="color: #2aa198; font-style: italic;">of its arguments."</span>
(interactive <span style="color: #2aa198;">"r"</span>)
(<span style="color: #859900;">unless</span> mark-active
(setf beg (point-min)
end (point-max)))
(<span style="color: #859900;">let</span> ((wc 0)
(latex-macro-regexp <span style="color: #2aa198;">"\\\\[</span><span style="color: #2aa198; font-weight: bold;">A-Za-z</span><span style="color: #2aa198;">]+</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">(</span><span style="color: #2aa198;">\\[[</span><span style="color: #2aa198; font-weight: bold;">^</span><span style="color: #2aa198;">]]*\\]</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">|</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">)</span><span style="color: #2aa198;">{</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">(</span><span style="color: #2aa198;">[</span><span style="color: #2aa198; font-weight: bold;">^</span><span style="color: #2aa198;">}]*</span><span style="color: #2aa198; font-weight: bold;">\\</span><span style="color: #2aa198; font-weight: bold;">)</span><span style="color: #2aa198;">}"</span>))
(<span style="color: #859900;">save-excursion</span>
(goto-char beg)
(<span style="color: #859900;">while</span> (<span style="color: #b58900;"><</span> (point) end)
(<span style="color: #859900;">cond</span>
<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">Ignore comments.</span>
((<span style="color: #b58900;">or</span> (org-in-commented-line) (org-at-table-p))
<span style="color: #b58900;">nil</span>)
<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">Ignore hyperlinks. But if link has a description, count</span>
<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">the words within the description.</span>
((looking-at org-bracket-link-analytic-regexp)
(<span style="color: #859900;">when</span> (match-string-no-properties 5)
(<span style="color: #859900;">let</span> ((desc (match-string-no-properties 5)))
(<span style="color: #859900;">save-match-data</span>
(incf wc (length (remove <span style="color: #2aa198;">""</span> (org-split-string
desc <span style="color: #2aa198;">"\\W"</span>)))))))
(goto-char (match-end 0)))
((looking-at org-any-link-re)
(goto-char (match-end 0)))
<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">Ignore source code blocks.</span>
((org-in-regexps-block-p <span style="color: #2aa198;">"^#\\+BEGIN_SRC\\W"</span> <span style="color: #2aa198;">"^#\\+END_SRC\\W"</span>)
<span style="color: #b58900;">nil</span>)
<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">Ignore inline source blocks, counting them as 1 word.</span>
((<span style="color: #859900;">save-excursion</span>
(backward-char)
(looking-at org-babel-inline-src-block-regexp))
(goto-char (match-end 0))
(setf wc (<span style="color: #b58900;">+</span> 2 wc)))
<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">Count latex macros as 1 word, ignoring their arguments.</span>
((<span style="color: #859900;">save-excursion</span>
(backward-char)
(looking-at latex-macro-regexp))
(goto-char (<span style="color: #859900;">if</span> count-latex-macro-args?
(match-beginning 2)
(match-end 0)))
(setf wc (<span style="color: #b58900;">+</span> 2 wc)))
<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">Ignore footnotes.</span>
((<span style="color: #b58900;">and</span> (<span style="color: #b58900;">not </span>count-footnotes?)
(<span style="color: #b58900;">or</span> (org-footnote-at-definition-p)
(org-footnote-at-reference-p)))
<span style="color: #b58900;">nil</span>)
(t
(<span style="color: #859900;">let</span> ((contexts (org-context)))
(<span style="color: #859900;">cond</span>
<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">Ignore tags and </span><span style="color: #cb4b16; background-color: #fdf6e3; font-style: italic;">TODO</span><span style="color: #93a1a1;"> keywords, etc.</span>
((<span style="color: #b58900;">or</span> (assoc <span style="color: #657b83; font-style: italic;">:todo-keyword</span> contexts)
(assoc <span style="color: #657b83; font-style: italic;">:priority</span> contexts)
(assoc <span style="color: #657b83; font-style: italic;">:keyword</span> contexts)
(assoc <span style="color: #657b83; font-style: italic;">:checkbox</span> contexts))
<span style="color: #b58900;">nil</span>)
<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">Ignore sections marked with tags that are</span>
<span style="color: #93a1a1; font-style: italic;">;; </span><span style="color: #93a1a1;">excluded from export.</span>
((assoc <span style="color: #657b83; font-style: italic;">:tags</span> contexts)
(<span style="color: #859900;">if</span> (intersection (org-get-tags-at) org-export-exclude-tags
<span style="color: #657b83; font-style: italic;">:test</span> 'equal)
(org-forward-same-level 1)
<span style="color: #b58900;">nil</span>))
(t
(incf wc))))))
(re-search-forward <span style="color: #2aa198;">"\\w+\\W*"</span>)))
(message (format <span style="color: #2aa198;">"%d words in %s."</span> wc
(<span style="color: #859900;">if</span> mark-active <span style="color: #2aa198;">"region"</span> <span style="color: #2aa198;">"buffer"</span>)))))
</pre>
</div>
</div>
</div>
<div id="outline-container-sec-1-3-8" class="outline-4">
<h4 id="sec-1-3-8">Check for misplaced SCHEDULED and DEADLINE cookies</h4>
<div class="outline-text-4" id="text-1-3-8">
<p>
The <code>SCHEDULED</code> and <code>DEADLINE</code> cookies should be used on the line <b>right
below</b> the headline – like this:
</p>
<div class="org-src-container">
<pre class="src src-org"><span style="color: #cb4b16;">* A headline</span>
, <span style="color: #93a1a1; font-size: 90%; font-style: italic;">SCHEDULED:</span> <span style="color: #268bd2; text-decoration: underline;"><2012-04-09 lun.></span>
</pre>
</div>
<p>
This is what <code>org-scheduled</code> and <code>org-deadline</code> (and other similar
commands) do. And the manual explicitely tell people to stick to this
format (see the section "8.3.1 Inserting deadlines or schedules").
</p>
<p>
If you think you might have subtrees with misplaced <code>SCHEDULED</code> and
<code>DEADLINE</code> cookies, this command lets you check the current buffer:
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">org-check-misformatted-subtree</span> ()
<span style="color: #2aa198; font-style: italic;">"Check misformatted entries in the current buffer."</span>
(interactive)
(show-all)
(org-map-entries
(<span style="color: #b58900;">lambda</span> ()
(<span style="color: #859900;">when</span> (<span style="color: #b58900;">and</span> (move-beginning-of-line 2)
(<span style="color: #b58900;">not </span>(looking-at org-heading-regexp)))
(<span style="color: #859900;">if</span> (<span style="color: #b58900;">or</span> (<span style="color: #b58900;">and</span> (org-get-scheduled-time (point))
(<span style="color: #b58900;">not </span>(looking-at (concat <span style="color: #2aa198;">"^.*"</span> org-scheduled-regexp))))
(<span style="color: #b58900;">and</span> (org-get-deadline-time (point))
(<span style="color: #b58900;">not </span>(looking-at (concat <span style="color: #2aa198;">"^.*"</span> org-deadline-regexp)))))
(<span style="color: #859900;">when</span> (y-or-n-p <span style="color: #2aa198;">"Fix this subtree? "</span>)
(message <span style="color: #2aa198;">"Call the function again when you're done fixing this subtree."</span>)
(recursive-edit))
(message <span style="color: #2aa198;">"All subtrees checked."</span>))))))
</pre>
</div>
</div>
</div>
<div id="outline-container-sec-1-3-9" class="outline-4">
<h4 id="sec-1-3-9">Sorting list by checkbox type</h4>
<div class="outline-text-4" id="text-1-3-9">
<p>
You can use a custom function to sort list by checkbox type.
Here is a function suggested by Carsten:
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">org-sort-list-by-checkbox-type</span> ()
<span style="color: #2aa198; font-style: italic;">"Sort list items according to Checkbox state."</span>
(interactive)
(org-sort-list
<span style="color: #b58900;">nil</span> ?f
(<span style="color: #b58900;">lambda</span> ()
(<span style="color: #859900;">if</span> (looking-at org-list-full-item-re)
(cdr (assoc (match-string 3)
'((<span style="color: #2aa198;">"[X]"</span> . 1) (<span style="color: #2aa198;">"[-]"</span> . 2) (<span style="color: #2aa198;">"[ ]"</span> . 3) (<span style="color: #b58900;">nil</span> . 4))))
4))))
</pre>
</div>
<p>
Use the function above directly on the list. If you want to use an
equivalent function after <code>C-c ^ f</code>, use this one instead:
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #859900;">defun</span> <span style="color: #268bd2;">org-sort-list-by-checkbox-type-1</span> ()
(<span style="color: #b58900;">lambda</span> ()
(<span style="color: #859900;">if</span> (looking-at org-list-full-item-re)
(cdr (assoc (match-string 3)
'((<span style="color: #2aa198;">"[X]"</span> . 1) (<span style="color: #2aa198;">"[-]"</span> . 2) (<span style="color: #2aa198;">"[ ]"</span> . 3) (<span style="color: #b58900;">nil</span> . 4))))
4)))