I've been trying to make an org capture template for storing quick ideas to my current project so I can get back to what I'm working on and evaluating the notes later.
This is the template code:
(setq org-capture-templates '(
("a" "quick notes" entry (file+olp "~/myproject" "NOTES" "IDEAS")
"") ))
When I hit C-c c a *** invent flying light bulb RET this is what I expect the target will look like:
* NOTES
** IDEAS
*** invent flying light bulb
Instead I get:
* NOTES
** IDEAS
*** invent flying light bulb
$THE-HEADING-THAT-THE-CURSOR-IS-ON
That is: whatever headline the cursor touches when 'org-capture is called is inserted along with my note. When I delete that string this appears:
[[file:~/$PATH-TO-FILE-I-WAS-WORKING-ON][]]
I haven't chosen any template expansions so why is this stuff inserted?
When using entry, the last field should not be blank. The example in the frequently asked questions for org-mode uses item when leaving the last field blank.
(setq org-capture-templates '(
("a" "quick notes" entry
(file+olp "~/Desktop/myproject.org" "NOTES" "IDEAS")
"*** %?") ))
Related
I am using many different org mode files for various projects, and I rev them by adding the date to the filename eg filename-2020-09-17.org. I realize I could use version control but in this case that is not possible, due to needing to share the file with others who are not using VC.
I would like the Agenda to always show just the items for the current file/buffer.
When I save eg the file with filename-2020-09-16.org to filename-2020-09-17.org, then the agenda still shows the old file name unless I remove it from the agenda file list and add the new file.
I realize that I can use C-c a < a but I am lazy and would rather not have to type S-, each time to get the <.
I looked at
Agenda view of the current buffer
And the OP says the solution was simple but he/she/they did not provide the solution - at least I don't see it and I tried the posted code but it no works.
I also found https://www.reddit.com/r/orgmode/comments/bxwovd/agenda_for_current_buffer/ but that did not seem to meet my need.
Specifically I would like to put something in .emacs so that this would apply to all files all the time.
I also looked into a keystroke macro programs but this does not seem ideal.
Any help is appreciated.
Thanks ahead of time.
Here's a simple function to do what you want, but there is no error checking to make sure e.g. that you are invoking it from a buffer that is visiting an Org mode file. The idea is that you set the org-agenda-files list to contain just the file which the buffer is visiting and then you call the regular org-agenda function. Binding the modified function to the C-c a key may or may not be what you want to do, but you can try and decide for yourself:
(defun org-agenda-current-buffer ()
(interactive)
(let ((org-agenda-files (list (buffer-file-name (current-buffer)))))
(org-agenda)))
(define-key global-map (kbd "C-c a") #'org-agenda-current-buffer)
I am learning how to use Emacs and org-mode, and am wondering whether Emacs can support tags within rather than just at the end of headlines (whether natively or through a package or configuration in ~/.emacs).
Put differently, Emacs natively supports tags in this form:
* This is a headline. :tag1:tag2:
Is there a way to get Emacs to recognize tags in the format below in addition?
* This is a headline with :tag1: and :tag2:.
I've been searching for answers for several hours, and haven't found this question anywhere else; I'd be grateful for any advice!
The real answer to this question is in #lawlist's comment above, that (to quote #lawlist) it "is not possible [to get org-mode to recognize tags within a line of text instead of at the end of the line] without substantially modifying several aspects of org-mode yourself."
For this reason, if #lawlist writes the comment up as an answer, I'll accept it. I'm also writing up this additional answer, though, for anyone like me who comes along and, learning this, wants a way to take some text and automatically generate org-mode tags for it. Following the discussion in the comments above, I've written a function in elisp below, which allows a user to highlight some text and automatically find any tags within the text (here, in the form {{tag}}) and concatenate them in org-mode tag format at the end of the first line.
(defvar tag-regexp-for-generating-org-mode-tag-list-from-text "{{\\(.*?\\)}}"
"A regular expression, in double-quotes, used for finding 'tags' within lines of text (these can then be translated into org-mode syntax tags.
For example, in the string \"This text contains the 'tags' {{tag1}} and {{tag2}}\", the default regular expression
\"{{\\(.*?\\)}}\"
would find \"tag1\" and \"tag2\", which could then be transformed into org-mode syntax tags, \":tag1:tag2:\"")
;; Following https://emacs.stackexchange.com/a/12335, use just the selected region.
(defun generate-org-mode-tag-list-from-selected-text (beginning-of-selected-region end-of-selected-region)
"Take a highlighted section of text, find all strings within that text that match the search parameters defined in the variable tag-regexp-for-generating-org-mode-tag-list-from-text (by default, strings of the form {{tag1}} {{tag2}}), and concatenate them into a set of org-mode tags (:tag1:tag2:)
When text is highlighted, the argumentes beginning-of-selected-region and end-of-selected-region will be automatically populated.
"
(interactive "r") ;; 'r' mode will auto-populate 'beginning-of-selected-region' and 'end-of-selected-region' above with the values of region-beginning and region-end.
(if (use-region-p) ;; If a region is actively highlighted
(progn ;; Start a multi-line sequence of commands
;; Following https://learnxinyminutes.com/docs/elisp/, go to the beginning-of-selected-region (here, of the selected region), and do a find-and-replace.
(setq list-of-tag-strings (list)) ;; Create a blank list, which we'll fill in below.
(goto-char beginning-of-selected-region) ;; Go to the beginning of the selected region (we'll then search forward from there.
;; A regex of "{{\\(.*?\\)}}" below looks for tags in {{this}} form. You can specify any other regex here instead.
(while (re-search-forward tag-regexp-for-generating-org-mode-tag-list-from-text end-of-selected-region 't) ;; Search forward, but only up to the end-point of the selected region (otherwise, end-of-selected-region could be replaced with nil here).
(add-to-list 'list-of-tag-strings ;; Add to the list called list-of-tag-strings
(replace-regexp-in-string "[[:space:]|:|-]+" "_" (match-string 1)) ;; Since org-mode tags cannot have spaces or colons (or dashes?) within them, replace any of those in the first capture group from the regular expression above ('match-string 1' returns whatever was in the parentheses in the regular expression above) with an underscore.
t) ;; Append (first checking for duplicate items) the first capture group from the regular expression above (i.e., what's inside the parentheses in the regular expression) to a list. The t tells the function to append (rather than prepend) to the list.
) ;; End of while statement
;; Go to the end of the first line of the selected region.
(goto-char beginning-of-selected-region)
(end-of-line)
(if (> (length list-of-tag-strings) 0) ;; If the length of the list of found tags is greater than 0:
(insert " " ":" (mapconcat 'identity list-of-tag-strings ":") ":")) ;; Insert two spaces, a ':', the items from the list each separated by a ':', and a final ':'.
(message "Tags gathered from the selected region (which comprises character markers %d to %d) and printed on the first line of the region." beginning-of-selected-region end-of-selected-region))
;; 'Else' part of the statement:
(message "No region is selected for gathering tags. To run the function, you need to highlight a region first.")
))
You can then highlight text like this, and run the function with M-x generate-tag-list-from-selected-text:
This is a test {{with}} some {{tags}} in it.
This is another test with an {{additional tag}} and {{one:more}}.
This text will then become
This is a test {{with}} some {{tags}} in it. :with:tags:additional_tag:one_more:
This is another test with an {{additional tag}} and {{one:more}}.
Since this is the first function I've written in elisp, I used two sources for understanding the basics of elisp syntax, specifically regarding a) using just a selected area of text and b) running find-and-replace operations on that text. Given that the function uses the generic structure of the code vs. its specific content, I'm thinking that I'm within my rights to open up the function with a CC0 dedication (I do this because of StackOverflow's ongoing discussion about licensing of code on this site).
EDIT: The solution was simple but "bonus points" for anyone that can explain why my method didn't work.
ORIG:
I would like an org-mode-custom-command to display an agenda which is only made from the current buffer.
The following snippet shows the kind of view that I want.
(setq org-agenda-custom-commands
'(("b" "Buffer summary"
((todo "TODO" ((org-agenda-files '("~/.agenda/notes.org"))))))))
But, I don't want to specify a filename, rather I want to use the current buffer. Here is my stab at it.
(setq org-agenda-custom-commands
'(("b" "Buffer summary"
((todo "TODO" ((org-agenda-files (buffer-file-name))))))))
When I open an org-buffer and run this agenda command the result is just a pretty much blank agenda view. I presume it's because buffer-file-name is being evaluated at point later than when I press the agenda view...?
I'm still beginning to learn elisp, so don't hesitate to point out the obvious. Thank-you.
EDIT:
Following a suggestion in the comments.
(setq org-agenda-custom-commands
'(("b" "Buffer summary"
((todo "TODO" ((org-agenda-files (list (buffer-file-name)))))))))
I receive a backtrace.
Debugger entered--Lisp error: (wrong-type-argument stringp nil)
file-directory-p(nil)
...etc...
For me, the most obvious is NOT to create an extra agenda view, and simply call any existing view on that buffer only (limit the view to the current buffer with a call such as C-c a < a, where < limits on the current buffer).
If you still want to make an extra agenda view for the current buffer, I'm not sure whether that's possible with all commands. For sure, calling occur-tree will work on the current buffer. Not sure about todo and the like.
...The agenda view usually shows the information collected from all the agenda files For more info, first make sure that file you are trying to make agenda-viwable or trackable, by activating it via an org command C-c [ (org-agenda-file-to-front)
you can test the current buffe name by
(message (buffer-file-name))
Normally, I use my agenda view from various files, but I can track different agendas e.g done, on-progress, fixed, bug, just by using hot-keys
Here is mine:
(setq org-agenda-custom-commands
'(
("x" agenda)
("y" agenda*)
("o" todo "ONPROGRESS")
("n" tags-todo "+TIPS")
("d" todo "DONE")
("p" todo "PENDING")
("b" todo "BUG")
("f" todo "FIXED")
;("F" todo-tree "FIXED")
))
So if I want to view e.g done stuffs C-c a d this will show me all done lists regardless of which file they came.
I hate assigning tags when the tag already exists in the headline. I'd like to figure out a way to have org-mode evaluate a headline (preferably right after I hit "enter") and, if it contains any words that match tags in my org-tag-alist, have those tags created for the headline.
As an example:
If I have various individual's names and various project names and possibly even terms like "today", "tomorrow", and "next week" already in my org-tag-alist then, when I type something like:
"TODO Remember to ask Joe tomorrow about the due dates for the XYZ project."
and hit enter, then the headline would be evaluated and the tags :Joe:XYZ:Tomorrow: would be generated for the item.
Has anyone seen something like this or have a suggestion as to how I could go about it myself?
This function gets the headline of the entry the point is one, splits it into words and adds as a tag any word it finds in either org-tag-alist or org-tag-persistent-alist
(defun org-auto-tag ()
(interactive)
(let ((alltags (append org-tag-persistent-alist org-tag-alist))
(headline-words (split-string (org-get-heading t t)))
)
(mapcar (lambda (word) (if (assoc word alltags)
(org-toggle-tag word 'on)))
headline-words))
)
It might be useful to add a function like this to org-capture-before-finalize-hook to automatically tag newly captured entries.
When using Org-mode and its LaTeX export BibTeX or Biblatex is often used to handle references. In that case the LaTeX command \printbibliography is often included in the org file. \printbibliography is placed in the org file where LaTeX is supposed to write out the reference list. What \printbibliography does is to insert a LaTeX header along with the reference list. In most cases \printbibliography is placed at the end of the org file simply because in most documents the reference list is to be placed last. This means that \printbibliography will be included under the last heading in the org file, e.g.
* Heading
\printbibliography
It also means that when that heading is folded the \printbibliography will be swallowed:
* Heading...
But this goes against the meaning of \printbibliography because it includes its own heading in the output. Also, it will be confusing when \printbibliography is swallowed and a new heading is placed after it because then the reference list will no longer appear last in the document.
How can I make it so that \printbibliography is not swallowed by sections in Org-mode? A bonus question: how can I make it so that Org-mode does not create headings after \printbibliography unless C-Ret is pressed when the cursor is after it?
In searching for a solution to this problem I found http://comments.gmane.org/gmane.emacs.orgmode/49545.
A workaround for this problem is to make \printbibliography not return a LaTeX heading so that it can appropriately be placed under an Org-mode heading.
With biblatex this can be done by supplying \printbibliography with the option heading=none and placing it under an appropriate heading. Here is an example:
* Heading
* References
\printbibliography[heading=none]
This way references can be kept in a heading of its own and \printbibliography being swallowed by a heading is not a problem because it is being swallowed by its own heading.
The following is lightly tested but works for me using tab and shift-tab to hide and display things. Those are the only hiding and showing commands that I use, so if you use other commands they may have to be advised or fixed in some other way.
You can of course change org-footer-regexp to anything you want. I was hoping to not have to use any advice, but without advising org-end-of-subtree the last heading never cycles with tab because it thinks it's not hidden, so it hides it and then org-cycle-hook unhides it. It calls org-end-of-subtree before running org-pre-cycle-hook so that's not an option either.
(defvar org-footer-regexp "^\\\\printbibliography\\[.*\\]$"
"Regexp to match the whole line of the first line of the footer which should always be shown.")
(defun show-org-footer (&rest ignore)
(save-excursion
(goto-char (point-max))
(when (re-search-backward org-footer-regexp nil t)
(outline-flag-region (1- (point)) (point-max) nil))))
(add-hook 'org-cycle-hook 'show-org-footer)
(add-hook 'org-occur-hook 'show-org-footer)
(defadvice org-end-of-subtree (after always-show-org-footer
()
activate)
(when (>= (point) (1- (point-max)))
(re-search-backward org-footer-regexp nil t)
(setq ad-return-value (point))))
One solution would be the following:
#+macro: printbiblio (add extra spaces here, but cannot add comment)
* Test 2
This is a test
* {{{printbiblio}}}
Test text
\printbibliography
*
asdf
Like this you end up with a blank heading at the bottom of the document. The macro expands to a blank block of text so you end up with
\section{Test 2}
\label{sec-1}
This is a test
\section{}
Test text
\printbibliography
\section{}
asdf
This also ensures you cannot accidentally add headlines after your bibliography, since it is it's own (empty) headline. It might be (seems to be actually) included in the table of contents, which is unfortunate but I would suspect the solution would be at worst run a post-export to remove the empty headline from the file (or manually do so before converting to PDF).
Another solution would be to put the bibliography under a heading named "References" like so:
* Heading
Some text
* References
\printbibliography
and remove the \section{References} from the resulting latex file by adding this to your emacs init file
(defun org-export-latex-remove-references-heading (contents backend info)
(if (not (eq backend 'latex))
contents
(replace-regexp-in-string "\\\\section\\*?{References}\\s-*\\\\label{.*?}" "" contents)
))
(add-hook 'org-export-filter-final-output-functions 'org-export-latex-remove-references-heading)
Note that this assumes you only have one heading that's named "References", as it replaces all occurrences of it. It also assumes the sections are in this format:
\section{References}
\label{<any_string>}
\printbibliography
For other formats you need to change the regular expression in the org-export-latex-remove-references-heading function.
* References
:PROPERTIES:
:UNNUMBERED: t
:END:
\printbibliography[heading=none]
There is an easier way to solve this.
Just add an "unnumbered" properties to the heading and it will be exported without any numbering.