I'd like to mix org-mode and c-mode in Emacs. Everything inside a
comment should be org-mode, the rests should be default major-mode
c-mode:
/*
Org-mode here
** Section 1
text
** Section 2
text
Org-mode should end here
*/
func1()
{
}
I tried using nXhtml multi-major-mode, I guess there are other modes
that support multimodes too. My problem now is that if I type TAB
on "section 2" then all below "Section 2" will be folded and
made invisible. But I would like to contain the region that org-mode
folds/unfolds to the comment section. The TAB should only fold/unfold
till the "*/".
I wonder how I can achieve this?
You can try M-x orgstruct-mode RET.
I found a solution:
http://lists.gnu.org/archive/html/emacs-orgmode/2011-01/msg00036.html
lists a patch for org-mode:
--- emacs-23.2/lisp/org/org.el 2010-04-04 00:26:08.000000000 +0200
+++ src/c51/mk/org.el 2011-01-02 20:26:10.266860827 +0100
## -5245,6 +5245,8 ##
(defun org-cycle-internal-local ()
"Do the local cycling action."
(org-back-to-heading)
+ (cond
+ ((not (looking-at (concat outline-regexp "\s*#" )))
(let ((goal-column 0) eoh eol eos level has-children children-skipped)
;; First, some boundaries
(save-excursion
## -5318,7 +5320,7 ##
(hide-subtree)
(message "FOLDED")
(setq org-cycle-subtree-status 'folded)
- (run-hook-with-args 'org-cycle-hook 'folded)))))
+ (run-hook-with-args 'org-cycle-hook 'folded)))))))
;;;###autoload
(defun org-global-cycle (&optional arg)
--- emacs-23.2/lisp/outline.el 2010-04-04 00:26:04.000000000 +0200
+++ src/c51/mk/outline.el 2011-01-02 20:35:17.303609833 +0100
## -913,8 +913,15 ##
;; Then unhide the top level headers.
(outline-map-region
(lambda ()
- (if (<= (funcall outline-level) levels)
- (outline-show-heading)))
+ (if (<= (funcall outline-level) level)
+ (if (looking-at (concat outline-regexp "\s*#" ))
+ (progn
+ (outline-show-heading )
+ (show-entry ))
+ (outline-show-heading))))
+;; (lambda ()
+;; (if (<= (funcall outline-level) levels)
+;; (outline-show-heading)))
beg end)))
(run-hooks 'outline-view-change-hook))
## -994,7 +1001,11 ##
(outline-map-region
(lambda ()
(if (<= (funcall outline-level) level)
- (outline-show-heading)))
+ (if (looking-at (concat outline-regexp "\s*#" ))
+ (progn
+ (outline-show-heading )
+ (show-entry ))
+ (outline-show-heading))))
(point)
(progn (outline-end-of-subtree)
(if (eobp) (point-max) (1+ (point)))))))
This patch has to be applied by hand, its not that difficult.
It adds the marker *# that will break the indention. #bzg pointed out
the M-x orgstruct-mode RET mode, credits to him. Now I can write in c.mode with orgstruct-mode in the background (no multi-major-mode needed any more):
/*
Org-mode here
** Section 1
text
** Section 2
text
*#
Org-mode should end here
*/
And I will have org-mode in comments, The Section 1 and Section 2 will fold until the *# marker.
Related
I would like to create a macro for emacs that will insert a latex comment block with some centerd text like:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Comment 1 %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Comment 2 Commenttext 3 %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Is this possible in emacs-lisp?
Emacs comes with the command comment-box for this purpose. It produces centered comment boxes, although the width of the box varies depending on the content. E.g., with the region set around the following line:
This is a comment
when you call M-x comment-box the text is transformed to:
;;;;;;;;;;;;;;;;;;;;;;;
;; This is a comment ;;
;;;;;;;;;;;;;;;;;;;;;;;
I use a modifed version that places the comment box around the current line if the region isn't active, and then steps out of the comment afterwards. It also temporarily reduces the fill-column, so the comment box is not wider than your longest line:
(defun ty-box-comment (beg end &optional arg)
(interactive "*r\np")
(when (not (region-active-p))
(setq beg (point-at-bol))
(setq end (point-at-eol)))
(let ((fill-column (- fill-column 6)))
(fill-region beg end))
(comment-box beg end arg)
(ty-move-point-forward-out-of-comment))
(defun ty-point-is-in-comment-p ()
"t if point is in comment or at the beginning of a commented line, otherwise nil"
(or (nth 4 (syntax-ppss))
(looking-at "^\\s *\\s<")))
(defun ty-move-point-forward-out-of-comment ()
"Move point forward until it's no longer in a comment"
(while (ty-point-is-in-comment-p)
(forward-char)))
Here's a yasnippet that you can use:
# -*- mode: snippet -*-
# name: huge_comment
# key: hc
# --
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%${1:$(repeat-char (- 33 (/ (length yas-text) 2)) " ")}$1${1:$(repeat-char (- 74 (length yas-text) (- 33 (/ (length yas-text) 2))) " ")}%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
$0
How to use it: type hc, call yas-expand and start typing the text. It will re-center itself
automatically.
This snippet will work from latex-mode or text-mode. I've noticed however a bug that
messes up the cursor position if you're using AUCTeX. In that case, you can momentarily switch
to text-mode.
The question was whether it is possible in emacs-lisp. Yes it is. There are several ways to do it.
I will show one way where you can also comment several lines of text.
Maybe, in the first line there is the title of the part of text and in the second one there is the author of this part.
A better way would be to advice LaTeX-indent-line function. This way you could edit the comment text and re-indent. When I find time I will show you also this variant.
Usage: Write your comment as clear text. Mark text as region with the mouse and then run the following command.
(defun LaTeX-centered-comment (b e)
"Convert region into centered comment."
(interactive "r")
(let* ((n (count-lines b e)))
(goto-char b)
(beginning-of-line)
(insert-char ?% fill-column)
(insert ?\n)
(setq b (point))
(center-line n)
(goto-char b)
(loop for i from 1 upto n do
(replace-region (point) (+ (point) 3) "%%%")
(end-of-line)
(insert-char ?\ (max 0 (- fill-column (- (point) (line-beginning-position)) 3)))
(insert "%%%")
(forward-line))
(insert-char ?% fill-column)
(insert ?\n)
))
The function (org-heading-components) and (org-element-property) produce integers for the number of stars and also for the priority. I'd like to store the entire headline as a variable and then use re-search-forward (or a similar function) to go back to that heading, but I foresee the problem that will occur when it cannot find an integer. I need to store the whole heading as a variable, because I often have todo entries with duplicate titles but the other components are diferent.
For example, the following todo:
** Active [#A] Ask the geniuses on stackoverflow how to do this. :lawlist:
when evaluated with (org-heading-components) looks like this:
(2 2 "Active" 65 "Ask the geniuses on stackoverflow how to do this." ":lawlist:")
So, when storing that as a variable and later using re-search-forward there will be problems because 2 2 is not the same as **, and 65 is not the same as [#A].
(defun lawlist ()
(interactive)
(let* (
(beg (point))
(complete-heading (org-heading-components) ))
* * *
(goto-char (point-min))
(re-search-forward complete-heading nil t) ))
You should be able to convert the output as follows:
The first # is the current level (# of stars)
The second number is the reduced headline level, applicable if org-odd-levels-only is set, but this is not regarding output.
Todo keyword
Priority character (65 is ASCII code for A)
Headline text
Tags or nil
The following will return the headline string as shown in the buffer. It will not work with re-search-forward but will work with search-forward (It does not escape any characters).
(defun zin/search-test ()
(interactive)
(let ((head (org-element-interpret-data (org-element-at-point))))
(message "%s" (format "%s" (car (split-string head "\n"))))))
This does not set it to any variable, you'll have to wrap it in an appropriate function that will set your desired variable. Then use (search-forward <var> nil t) to match it, without it erroring out if it cannot find it.
There's a brilliant part of org that might suit you: org-id-copy and
org-id-goto. It works with precision across buffers and sessions:
org-id-copy produces a string. You can feed that string to
org-id-goto which will take you to that heading. Even if you've
closed the original buffer. Even if you've restarted Emacs.
EDIT (December 15, 2013): Updated solution based upon the variable org-heading-regexp (defined within org.el) and a modification thereof to include (if it exists) a second line containing a deadline - i.e., lawlist-org-heading-regexp. The revision also includes a nifty function regexp-quote that was just taught to me by #Drew over on superuser: https://superuser.com/questions/688781/how-to-highlight-string-and-unhighlight-string-in-buffer-make-overlay?noredirect=1#comment874515_688781 (buffer-substring-no-properties beg end) is used to set the string as a variable.
EDIT (December 17, 2013): Added isearch-highlight and isearch-dehighlight, and commented out highlight-regexp and unhighlight-regexp. When moving the point around with more complex functions, highlight-regexp does not reliably highlight the entire string -- this may be because the screen has not refreshed, or it may also be caused by other factors -- e.g., hl-line-mode, etc.) -- placing various sit-for 0 did not fix the issue with highlight-regexp -- isearch-highlight works better.
EDIT (January 6, 2014): See also this related thread for a complete regexp to match any element of the entire todo from stars through to the end of the notes: https://stackoverflow.com/a/20960301/2112489
(require 'org)
(defvar lawlist-org-heading-regexp
"^\\(\\*+\\)\\(?: +\\(.*?\\)\\)?[ \t]*\\(\n.*DEADLINE.*$\\)"
"Match headline, plus second line with a deadline.")
(defun example ()
(interactive)
(switch-to-buffer (get-buffer-create "foo"))
(org-mode)
(insert "* Example\n\n")
(insert "** Active [#A] This is an active todo. :lawlist:\n")
(insert " DEADLINE: <2013-12-15 Sun 08:00> SCHEDULED: <2013-12-15 Sun>\n\n")
(insert "** Next-Action [#B] This is an inactive todo. :lawlist:\n")
(insert " DEADLINE: <2013-12-16 Mon 08:00> SCHEDULED: <2013-12-16 Mon>")
(goto-char (point-min))
(sit-for 2)
(re-search-forward (regexp-quote "** Active [#A] "))
(sit-for 2)
(let ((init-pos (point)))
(org-back-to-heading t)
(let* (
lawlist-item-whole
lawlist-item-partial
(beg (point)))
(if (and
(looking-at org-heading-regexp)
(and (looking-at lawlist-org-heading-regexp) (match-string 3)))
(re-search-forward lawlist-org-heading-regexp nil t)
(re-search-forward org-heading-regexp nil t))
(let ((end (point)))
(setq lawlist-item-whole (buffer-substring-no-properties beg end))
(setq lawlist-item-partial (buffer-substring-no-properties beg init-pos))
(re-search-backward (regexp-quote lawlist-item-whole) nil t)
;; (highlight-regexp (regexp-quote lawlist-item-whole))
(isearch-highlight beg end)
(sit-for 2)
;; (unhighlight-regexp (regexp-quote lawlist-item-whole))
(isearch-dehighlight)
(re-search-forward (regexp-quote lawlist-item-partial) nil t)
(sit-for 2)
(kill-buffer "foo")))))
EDIT (October 27, 2013): Prior solution that is being preserved temporarily as a historical part of the evolution process towards a final answer. However, it is no longer a preferred method.
(defun lawlist-org-heading-components ()
(org-back-to-heading t)
(if (let (case-fold-search) (looking-at org-complex-heading-regexp))
(concat
(cond
((equal (org-match-string-no-properties 1) "**")
"^[*][*]")
((equal (org-match-string-no-properties 1) "*")
"^[*]"))
(cond
((and (match-end 2) (aref (match-string 2) 1))
(concat " " (org-match-string-no-properties 2))))
(cond
((and (match-end 3) (aref (match-string 3) 2))
(concat " \\" (org-match-string-no-properties 3))))
(cond
((and (match-end 4) (aref (match-string 4) 3))
(concat " " (org-match-string-no-properties 4))))
(cond
((and (match-end 5) (aref (match-string 5) 4))
(concat " " (org-match-string-no-properties 5)))))))
I'm using org-mode for organizing myself (very useful so far!). However, it is kind of annoying writting
#+begin_comment
...
#+end_comment
each time I'd like to insert an environment.
Question
Is there a shortcut to insert the #+begin_ and #+end_ for a given environment?
In the same way C-c C-o comment RET would insert
\begin{comment}
\end{comment}
in latex-mode.
Org has a facility called "Easy templates": http://orgmode.org/manual/Easy-Templates.html
A template for comment is missing but you can add it with:
(add-to-list 'org-structure-template-alist '("C" "#+begin_comment\n?\n#+end_comment"))
And use it by typing <C followed by TAB.
Alternatively, you could use yasnippet.
Now the corresponding template section is called Structure Template and the insertion sequence is invoked by C-c C-,. I didn't (require 'org-tempo) which is described to support insertion keys like <s TAB.
The comment environment is already defined in org-structure-template-alist. So the comment would be inserted by
C-c C-, C
It's still possible to add a user defined sequence by, for example,
C-c C-, [TAB|RET|SPC] src python :results output :session
delivering
#+begin_src python :results output :session
#+end_src
(emacs 25.2.2, org-mode 9.2)
You could have a look at "org-auctex-keys.el", a minor mode which I created to offer AUCTeX key bindings within Org documents.
In this case, you'd use C-c C-e to insert an environment (prompt to enter the environment name), as what AUCTeX does.
If you're interested, check it out at https://github.com/fniessen/org-auctex-key-bindings.
Not as elegant as the answer of Michael Markert but maybe more expandable.
1) You can select a region and put the block around it or you can just put the block at point.
2) Keyword expansion and history.
3) Keystrokes: C-c b
The command could be further expanded. E.g., for the src block the various switches like -n -r and export to files could be supported.
(defun list-major-modes ()
"Returns list of potential major mode names (without the final -mode).
Note, that this is guess work."
(interactive)
(let (l)
(mapatoms #'(lambda (f) (and
(commandp f)
(string-match "-mode$" (symbol-name f))
;; auto-loaded
(or (and (autoloadp (symbol-function f))
(let ((doc (documentation f)))
(when doc
(and
(let ((docSplit (help-split-fundoc doc f)))
(and docSplit ;; car is argument list
(null (cdr (read (car docSplit)))))) ;; major mode starters have no arguments
(if (string-match "[mM]inor" doc) ;; If the doc contains "minor"...
(string-match "[mM]ajor" doc) ;; it should also contain "major".
t) ;; else we cannot decide therefrom
))))
(null (help-function-arglist f)))
(setq l (cons (substring (symbol-name f) 0 -5) l)))))
(when (called-interactively-p 'any)
(with-current-buffer (get-buffer-create "*Major Modes*")
(clear-buffer-delete)
(let ((standard-output (current-buffer)))
(display-completion-list l)
(display-buffer (current-buffer)))))
l))
(defvar org-insert-block-hist nil
"History for command `org-insert-block'")
(defvar org-insert-block-hist/src:major nil
"History for major mode in org src blocks.")
(defvar org-insert-block-list (append org-protecting-blocks
'("comment" ""))
"List of block types offered as completion for command `org-insert-block'")
;; block_src switches: -n () -r (references) -l "((%s))" (label format) -k (keep labels)
(defvar org-insert-block-list-specials
"Assoc list of Commands for reading additional specification of org-blocks.")
(setq org-insert-block-list-specials
'(("src" . (concat " " (completing-read "Major mode:"
(list-major-modes)
nil nil
(car org-insert-block-hist/src:major)
'(org-insert-block-hist/src:major . 1)
)))))
(defun org-insert-block (bl &optional b e attributes)
"Put region between b and e into org-block of kind bl.
If b or e is nil then put org-block limiters around point.
The string attributes is inserted behind the string #+begin_... "
(interactive
(let ((usereg (use-region-p))
(blKind (completing-read "Input block kind (tab: completion, uparrow: history):"
org-insert-block-list nil nil (car org-insert-block-hist) '(org-insert-block-hist . 1))))
(list
blKind
(when usereg (region-beginning))
(when usereg (region-end))
(let ((spec (assoc blKind org-insert-block-list-specials)))
(when spec (eval (cdr spec)))
))))
(let ((begBlock (concat "\n#+begin_" bl attributes "\n"))
(endBlock (concat "\n#+end_" bl "\n")))
(if (and b e)
(save-restriction
(narrow-to-region b e)
(goto-char (point-min))
(insert begBlock)
(goto-char (point-max))
(insert endBlock)
(indent-region (point-min) (point-max)))
(let ((p (point)))
(insert endBlock)
(goto-char p)
(insert begBlock))
)))
(add-hook 'org-mode-hook '(lambda ()
(local-set-key (kbd "C-c b") 'org-insert-block)))
Using Emacs org-mode, I often have a list of TODO items that I want to have active one at a time, in sequence. For example when the Item A in a list is marked "DONE", then I want Item B to be automatically be marked "TODO". How do I make this happen? This should not be any kind of general behavior, it should only happen with specific pairs or lists of items that I chose.
;; init-org-lawlist.el
;;
;; QUESTION #Brian Z -- stackoverflow.com: "How to automatically trigger a change in TODO state in Emacs org-mode."
;;
;; "I often have a list of TODO items that I want to have active one at a time, in sequence. For example when the
;; Item A in a list is marked "DONE", then I want Item B to be automatically be marked "TODO". How do I make this
;; happen? This should not be any kind of general behavior, it should only happen with specific pairs or lists of
;; items that I chose."
;;
;;
;; ANSWER #lawlist -- stackoverflow.com -- This script provides two (2) possible options:
;;
;; 1. Navigate to a ** TODO heading (must have at least one todo subtree underneath) and enter: M-x lawlist-done
;; OR
;; 2. Within a ** TODO heading (must have at least one todo subtree underneath), Shift-Right or Shift-Left and cycle
;; to the option ** DONE and then confirm yes or no.
;;
;; NOTE # A: This configuration script assumes the `org-archive-location` will use the SAME lawlist.org file for everything.
;; In this example, the script uses: (setq org-archive-location "/Users/HOME/.0.data/lawlist.org::* ARCHIVES")
;;
;; NOTE # B: Whenever using setq . . ., there is a likelihood that other settings with the same variable will be trumped.
;; So, after testing this script, it would be best to mix and match portions you like with your own configuration for org-mode.
;; You may need to temporarily disable your other configurations that use the same setq variables so as not to conflict while
;; testing this script.
;;
;; NOTE # C: Author to consider adding a check for the existence of at least one subsequent todo subtree as a condition precedent.
;;
;; NOTE # D: Author to consider adding a check that the user is on a second level tier (i.e., a todo) as a condition precedent.
;;
;;
;;
;;
;; SAMPLE lawlist.org CONFIGURATION FILE
;;
;;
;; * TASKS
;;
;; ** TODO [#A] First, figure out this new feature request. :lawlist:
;; DEADLINE: <2013-07-09 Tue>
;; :PROPERTIES:
;; :lawlist-drawer: ACTIVE
;; :END:
;;
;; ** NEXT [#B] Second, If at first you don't succeed, then try again. :lawlist:
;; :PROPERTIES:
;; :lawlist-drawer: PENDING
;; :END:
;;
;; ** WAITING [#C] Third, try again to figure out this new feature request. :lawlist: :WAITING:
;; :PROPERTIES:
;; :lawlist-drawer: DORMANT
;; :END:
;;
;; ** HOLD [#D] Fourth, try, try again to figure out this new feature request. :lawlist: :WAITING:HOLD:
;; :PROPERTIES:
;; :lawlist-drawer: DORMANT
;; :END:
;;
;;
;; * ARCHIVES
;;
;; ** DONE [#E] This task is a done deal. :lawlist:
;; :PROPERTIES:
;; :lawlist-drawer: COMPLETED
;; :END:
(require 'org)
(setq org-startup-folded 'showeverything) ;; overview | content | all | showeverything
(setq org-tags-column 0)
(setq org-startup-indented nil)
(setq org-indent-mode nil)
(setq org-support-shift-select t) ;; 'always to disable; or, t to use shift-select only when cursor is within a special context.
(setq org-cycle-separator-lines 1)
(setq org-insert-heading-respect-content t)
(setq org-blank-before-new-entry '((heading . t) (plain-list-item . nil)))
(setq org-enable-priority-commands t)
(setq org-highest-priority ?A)
(setq org-lowest-priority ?E)
(setq org-default-priority ?A)
(setq org-ellipsis " \u25bc" )
;; '!' (for a timestamp) or '#' (for a note with timestamp)
(setq org-todo-keywords
(quote ((sequence "TODO(t)" "NEXT(n)" "WAITING(w)" "HOLD(h)" "|" "DONE(d)" "CANCELED(c)") )))
(setq org-global-properties '(("lawlist-drawer_ALL". "ACTIVE PENDING DORMANT COMPLETED")))
(setq org-default-properties (cons "lawlist-drawer" org-default-properties))
(setq org-todo-state-tags-triggers
(quote (("CANCELED" ("CANCELED" . t))
("WAITING" ("WAITING" . t))
("HOLD" ("WAITING" . t) ("HOLD" . t))
(done ("WAITING") ("HOLD"))
("TODO" ("WAITING") ("CANCELED") ("HOLD"))
("NEXT" ("WAITING") ("CANCELED") ("HOLD"))
("DONE" ("WAITING") ("CANCELED") ("HOLD")))))
(setq org-tag-alist (quote ((:startgroup)
("john-doe" . ?j)
("jane-doe" . ?J)
(:endgroup)
("lawlist" . ?0))))
(add-hook 'org-after-todo-state-change-hook 'lawlist-hook)
(defun lawlist-hook (&optional default-heading)
(let ((lawlist-item default-heading)
result)
(unless lawlist-item
(condition-case nil
(progn
(org-back-to-heading t)
(setq lawlist-item (elt (org-heading-components) 4)))
)
)
(when (string-equal org-state "DONE")
(if (string-equal org-state "DONE")
(or (yes-or-no-p (format "%s -- process?" org-state))
(error "You changed your mind.")))
(org-forward-heading-same-level 1)
(org-todo "TODO")
(org-priority ?A)
(org-deadline nil "<%<%Y-%m-%d %a>>")
(org-set-property "lawlist-drawer" "ACTIVE")
(org-backward-heading-same-level 1)
(org-priority ?E)
(org-deadline 'remove)
(org-set-property "lawlist-drawer" "COMPLETED")
;; (setq org-archive-save-context-info nil) ;; Set to nil if user doesn't want archive info.
;; NOTE: User must set the correct path to his / her lawlist.org file.
(setq org-archive-location "/Users/HOME/.0.data/lawlist.org::* ARCHIVES")
(org-archive-subtree)
(goto-char (point-min))
(re-search-forward "^\* ARCHIVES" nil t)
(org-sort-entries t ?a)
;; (org-sort-entries t ?d) additional sorting criteria if deadline is not removed.
(lawlist-org-cleanup)
(goto-char (point-min))
(re-search-forward lawlist-item nil t)
(beginning-of-line)
(message "Please take a moment to visually verify your completed tasks has been refiled correctly, then press any key.")
(read-event) )))
(defun delete-trailing-blank-lines-at-end-of-file ()
"Deletes all blank lines at the end of the file, even the last one"
(interactive)
(save-excursion
(save-restriction
(widen)
(goto-char (point-max))
(delete-blank-lines)
(let ((trailnewlines (abs (skip-chars-backward "\n\t"))))
(if (> trailnewlines 0)
(progn
(delete-char trailnewlines)))))))
(defun lawlist-org-cleanup ()
(interactive)
(save-excursion
(replace-regexp "\n+\\*\\* " "\n\n** " nil (point-min) (point-max))
(replace-regexp "\n+\\* " "\n\n\n* " nil (point-min) (point-max))
(replace-regexp "\n\t\s*" "\n " nil (point-min) (point-max)) )
(delete-trailing-blank-lines-at-end-of-file) )
(defun lawlist-done (&optional default-heading)
(interactive)
(remove-hook 'org-after-todo-state-change-hook 'lawlist-hook)
(let ((lawlist-item default-heading)
result)
(unless lawlist-item
(condition-case nil
(progn
(org-back-to-heading t)
(setq lawlist-item (elt (org-heading-components) 4)))
)
)
(org-forward-heading-same-level 1)
(org-todo "TODO")
(org-priority ?A)
(org-deadline nil "<%<%Y-%m-%d %a>>")
(org-set-property "lawlist-drawer" "ACTIVE")
(org-backward-heading-same-level 1)
(org-todo "DONE")
(org-priority ?E)
(org-deadline 'remove)
(org-set-property "lawlist-drawer" "COMPLETED")
;; (setq org-archive-save-context-info nil) ;; Set to nil if user doesn't want archive info.
;; NOTE: User must set the correct path to his / her lawlist.org file.
(setq org-archive-location "/Users/HOME/.0.data/lawlist.org::* ARCHIVES")
(org-archive-subtree)
(goto-char (point-min))
(re-search-forward "^\* ARCHIVES" nil t)
(org-sort-entries t ?a)
;; (org-sort-entries t ?d) additional sorting criteria if deadline is not removed.
(lawlist-org-cleanup)
(goto-char (point-min))
(re-search-forward lawlist-item nil t)
(beginning-of-line))
(add-hook 'org-after-todo-state-change-hook 'lawlist-hook) )
(provide 'init-org-lawlist)
The lawlist.org sample file used for testing the script should look exactly like this:
* TASKS
** TODO [#A] First, figure out this new feature request. :lawlist:
DEADLINE: <2013-07-09 Tue>
:PROPERTIES:
:lawlist-drawer: ACTIVE
:END:
** NEXT [#B] Second, If at first you don't succeed, then try again. :lawlist:
:PROPERTIES:
:lawlist-drawer: PENDING
:END:
** WAITING [#C] Third, try again to figure out this new feature request. :lawlist: :WAITING:
:PROPERTIES:
:lawlist-drawer: DORMANT
:END:
** HOLD [#D] Fourth, try, try again to figure out this new feature request. :lawlist: :WAITING:HOLD:
:PROPERTIES:
:lawlist-drawer: DORMANT
:END:
* ARCHIVES
** DONE [#E] This task is a done deal. :lawlist:
:PROPERTIES:
:lawlist-drawer: COMPLETED
:END:
You're not giving a lot of context here, is this what you want?
(defun org-todo-plus ()
(interactive)
(org-todo)
(org-forward-element)
(org-todo))
It works for this list:
* TODO spam
* eggs
* foo
* bar
With point on spam, just keep M-x org-todo-plus until everything is done.
There are Tags as in #+AUTHOR or #+LATEX in org-mode - are they called tags? I'd like to define my own tag which calls a function to preprocess the data and then outputs it - if the export target is LaTeX.
My solution was defining an own language, qtree, for SRC blocks.
#+BEGIN_SRC qtree
[.CP [.TP [.NP [] [.N' [.N Syntax] []]] [.VP [] [.V' [.V sucks] []]]]]
#+END_SRC
And process it accordingly. I even added a qtree-mode with paredit.
And a landscape parameter if the trees grow big. https://github.com/Tass/emacs-starter-kit/blob/master/vendor/assorted/org-babel-qtree.el
(require 'org)
(defun org-babel-execute:qtree (body params)
"Reformat a block of lisp-edited tree to one tikz-qtree likes."
(let (( tree
(concat "\\begin{tikzpicture}
\\tikzset{every tree node/.style={align=center, anchor=north}}
\\Tree "
(replace-regexp-in-string
" \\_<\\w+\\_>" (lambda (x) (concat "\\\\\\\\" (substring x 1)))
(replace-regexp-in-string
(regexp-quote "]") " ]" ; qtree needs a space
; before every closing
; bracket.
(replace-regexp-in-string
(regexp-quote "[]") "[.{}]" body)) ; empty leaf
; nodes, see
; http://tex.stackexchange.com/questions/75915
) ; For
; http://tex.stackexchange.com/questions/75217
"\n\\end{tikzpicture}"
)))
(if (assoc :landscape params)
(concat "\\begin{landscape}\n" tree "\n\\end{landscape}")
tree)))
(setq org-babel-default-header-args:qtree '((:results . "latex") (:exports . "results")))
(add-to-list 'org-src-lang-modes '("qtree" . qtree))
(define-generic-mode
'qtree-mode ;; name of the mode to create
'("%") ;; comments start with '%'
'() ;; no keywords
'(("[." . 'font-lock-operator) ;; some operators
("]" . 'font-lock-operator))
'() ;; files for which to activate this mode
'(paredit-mode) ;; other functions to call
"A mode for qtree edits" ;; doc string for this mode
)
They seem to be called keywords for in-buffer settings no more. Whatever they're called, they don't seem to be user-definable.
What you want to do is extremely related to a common way of handling whereas to export with xelatex or pdflatex as described on Worg.
The relevant part would be :
;; Originally taken from Bruno Tavernier: http://thread.gmane.org/gmane.emacs.orgmode/31150/focus=31432
(defun my-auto-tex-cmd ()
(if (string-match "YOUR_TAG: value1" (buffer-string))
(do something))
(if (string-match "YOUR_TAG: value2" (buffer-string))
(do something else))
(add-hook 'org-export-latex-after-initial-vars-hook 'my-auto-tex-cmd)