org-mode - no refile targets - org-mode

I am trying to use the refile function but don't understand why I get the error
no refile targets after hitting the Cc Cw key.
Here is the content of org-refile-targets variable :
Its value is (("~/gtd/gtd.org" :maxlevel . 3) ("~/gtd/someday.org" :level . 1) ("~/gtd/tickler.org" :maxlevel . 2))
Original value was nil and defined through this function in .emacs
(setq org-refile-targets '(("~/gtd/gtd.org" :maxlevel . 3)
("~/gtd/someday.org" :level . 1)
("~/gtd/tickler.org" :maxlevel . 2)))
All those files exist in the gtd folder. I can capture elements that I are stored into the ~/gtd/inbox.org file.
I am relatively new to the emacs/org-mode world, the error might be quite stupid.

It seems like you're following along with Nicolas Petton's Orgmode for GTD article; I ran into the same issue this morning.
org-refile searches for headings within the files in org-refile-targets, up to the level specified. So in your example, org-refile will find headings up to level 3 in ~/gtd/gtd.org, level 2 in ~/gtd/tickler.org, and only level 1 in ~/gtd/someday.org. These will then be offered as targets for your refile operation.
To fix this error, simply create some headings in one or more of those files.

I had a similar problem which I managed to solve after reading this, so I thought I'd add that solution as well in case it helps others.
I'm currently, through no fault of my own, using Windows. Therefore, I had my paths in my org-refile-targets set up like this:
"C:\Path\to\orgfile.org"
I wasn't thinking properly - those backslashes are interpreted. So the solution was to switch from backslashes to slashes (which works in Emacs even in Windows):
"C:/Path/to/orgfile.org"
I'm guessing that double backslashes would also have worked.

Related

How can I treat certain patterns as web-site links, that can be followed with org-open-at-point?

At work I frequently deal with support issues that my company keeps track of in a web-based bug tracker.
Each issue has an URL that looks like https://mycompany.com/support/SUPPORT-12345, but of course I don't want to spell this out every time I mention a support issue in my Org-mode file. I would like set up Org-mode in such a way that the pattern SUPPORT-(\d+) is treated as a hyperlink to https://mycompany.com/support/SUPPORT-\1.
I would like to be able to place my cursor over the SUPPORT-2345, type C-c C-o, and have Emacs point my browser to https://mycompany.com/support/SUPPORT-2345. Ideally, SUPPORT-2345 would behave no different than a hyperlink.
Can Org-mode be configured in this way? If not, what is the best alternative?
You should be able to do this with org-link-abbrev-alist. For example, see the below for some I use. You can then put [[Support:1234]] in your Org-mode file and have it treated as the expanded link.
(setq org-link-abbrev-alist
'(
("DOI" . "http://dx.doi.org/")
("FreshDesk" . "https://xyz.freshdesk.com/support/tickets/")
("JIRA" . "https://jira.apps.monash.edu/browse/")
("Support" . "https://support.xyz.com/helpdesk/tickets/")
("ISBN" . "http://isbn.nu/")))
I don't know whether Org-mode have this feature, but there is a bug-reference-mode for it.
Here is sample org file:
;; Local Variables:
;; eval: (bug-reference-mode)
;; bug-reference-bug-regexp: "\\(\\(?:\\(?:SUPPORT\\|support\\)-\\)\\([0-9]+\\)\\)"
;; bug-reference-url-format: "https://mycompany.com/support/SUPPORT-%s"
;; End:
* SUPPORT-123
* support-1234
And you can move point on support-* and press C-c RET (bug-reference-push-button) to open it.
For more detail about Bug Reference, please refer to C-h r g Bug Reference

Configuring Org-Gcal to have subheadings within Spacemacs

this is a bit of a complicated case, so I will try to be as brief as possible.
I would like to use sub headings (level 2+) in org-gcal within Spacemacs. However, the sync currently only allows for level 1 syncing. However, I have manually tested replacing lvl 2 headers ** and replaced with -- (start at the beginning of a line or ^). This allows org-gcal to sync the sub-headers to the notes section of Google Calendar and allows me to take quick notes while out and about. My goal would be to automate a text replacement procedure of all *.org files w/i a specified directory by using a single custom command and ...
(a) convert all ** # beginning of lines to -- on all files w/i specified directory (b) run org-gcal-sync to sync the modified files (c) once files are synced, reverse process and convert all -- back to ** and allow for org-mode functionality of column view, etc.
Specifically, I am using the following packages... 1) https: //github.com/sineer/spacemacs-calendar-layer (implementation of org-gcal in Spacemacs) 2) http: //melpa.org/#/xah-find (for text replacement)
I have narrowed the code down to using either xah-find-replace-text or (preferably) xah-find-replace-text-regex. However, I am pretty sure I am having issues with regex, scope, and lisp commands in general. Details are below. To be clear, if the following is too complicated or there is a much easier solution, I am open to any suggestions. Thanks in advance!!!
(xah-find-replace-text "aaa" "bbb" "~/emacs/org/Test/." ".org\'" "y" "y" "y" "y")
Using the interactive mode (C-x C-e), I have tested the above and it will replace all instances of "aaa" with "bbb", but I would prefer to use something more along the lines of (xah-find-replace-text-regex "^**" "--" "~/pathToDir" "y" "y" "y") since the matches would be more specific to the start of a line. Please note that the regex version takes 7 parameters (compared to the xah-find-replace-text which takes 8).
Eventually, I would prefer to automate by placing something similar into my .init/.Spacemacs file...
(defun org-gcal-sync-subchildren ()
(interactive)
(xah-find-replace-text-regex "^\*\\*" "--"......etc.)
(org-gcal-sync)
(xah-find-replace-text-regex "^--" "**".......etc.))
For reference: Org-Gcal: 1) current issue: https: //github.com/myuhe/org-gcal.el/issues/43
xah-find: 1) regular text find: https: //github.com/xahlee/xah-find/blob/master/xah-find.el#L556 2) Regex text find and replace: https: //github.com/xahlee/xah-find/blob/master/xah-find.el#L642
Sorry for the broken links, but my reputation does not allow me to post more than two.
Looks like your issues is the regex.
This should work:
(xah-find-replace-text-regex "^\\*\\* " "-- " "~/emacs/org/Test/." "\\.org\\'" nil t t)
(xah-find-replace-text-regex "^-- " "** " "~/emacs/org/Test/." "\\.org\\'" nil t t)
Test them. If works, replace the nil to t (for write file)
You need double slash in elisp string for regex.

Lisp: creating a macro to cycle through a created list per document

Let's say I want to create a new document, and cycle quickly through a list.
If it's only for one "word", I think there should be a general way to do this.
For instance:
"blue orange red yellow black white"
Does anyone know a way how to cycle through those items when I create:
\begin{orange}
... and I want to press a key to cycle through this list, replacing orange with the next item on the list (doing this procedure in the opposite direction wouldn't be hard then)?
I tried many different ideas with macro's (placing the list on the top of the document, and doing a whole bunch of i-searches), but that doesn't cut it.
I'd be willing to put the list in an elisp file, though I have no clue how to use that variable from elisp in, let's say, a LaTeX document (.tex).
Well, this might be possible, but depends on how much effort you are willing to put into writing eLisp code to make it work. It's not possible by just some configuration option. I would be looking into extending autocomplete by adding new sources to it, something like:
(defvar tex-tag-ac-sources
'((init . tex-tag-ac-init)
(requires . 0)
(candidates . tex-tag-ac-candidates)
(document . tex-tag-ac-documentation)
(match . tex-tag-completion-filter)
(prefix . tex-tag-ac-prefix-matcher)
(symbol . "s"))
"The source generator for autocompletion needed for interaction
with auto-complete")
Where tex-tag-ac-candidates, tex-tag-ac-documentation, tex-tag-completion-filter and tex-tag-ac-prefix-matcher are function that do autocompletion. I.e. init function is called once when the autocompletion process starts for a specified prefix. It's called w/o arguments. The candidates is the function that is responsible for showing the filtered list of candidates, it's called w/o arguments, you would filter the candidates in the filter function, it is called with the prefix collected so far and the list of candidates so far. Lastly, the matcher function is invoked on the text of the file to see if the completion is needed at point. So, if it returns t, the init is called, and then loops through filter-candidates as you type.
While this is a bit involved... you'd definitely have a completion for anything you want. Obviously, if those functions in source are defined by you, then, if you wanted to, you could read completion arguments dynamically or have them generated dynamically in some way.
Ah, you would add the sources to autocomplete by something like:
(auto-complete (list tex-tag-ac-sources))
if doing it on per call basis, or
(setq ac-sources (list tex-tag-ac-sources <other sources>))
You can find more info here: http://cx4a.org/software/auto-complete/manual.html#Using_Source
EDIT: I translated the macro into a function.
Here is a way I did it. I created a file called "list.list" where my "lists" are saved. I saved the LaTeX templates for Beamer in there. I inserted them like this:
Antibes Bergen Berkeley Berlin ..... Antibes
Note that you should always put the first entry in twice to allow it to loop.
Here is the code:
(defun cycle-list-word ()
(interactive)
(right-word)
(backward-kill-word 1)
(find-file "/emacs-24.1/list.list")
(search-forward (substring-no-properties (car kill-ring)) nil t)
(right-word)
(backward-kill-word 1)
(bury-buffer)
(yank)
)

show hidden files in speedbar

Is there a way to display what the docs call level 2 hidden files in the speedbar? E.g. .emacs
Long Answer
It turns out that the unshown files are controlled by a regular expression
Which is usually "^\\(\\..*\\)\\'", which I think means everything that starts with a dot
Setting that regexp with:
(setq speedbar-directory-unshown-regexp "^$")
does the trick of showing everything.
While looking at this, I discovered that there is a bug in the default value of
speedbar-directory-unshown-regexp causing the problem. It should be redefined like this:
(setq speedbar-directory-unshown-regexp "^\\(CVS\\|RCS\\|SCCS\\|\\.\\.*$\\)\\'")
or to whatever you think makes the most sense.

GNU Emacs: skeleton-mode, is it still used?

given all the possible solutions to have a template system with GNU Emacs, what do people use today ? I am still using skeleton-mode but as I read it here and there, we must be really few to do so.
What are you using and why ? (maybe I could switch to a more popular tool).
For example, given this snippet:
(define-skeleton mwe:cl-defpackage-skeleton
"Inserts a Common Lisp DEFPACKAGE skeleton."
(skeleton-read "Package: " (if v1
(file-name-sans-extension
(file-name-nondirectory
(buffer-file-name)))))
(if (setq v1 (bobp)) ";;; -*- Mode:Lisp; Syntax:ANSI-Common-Lisp;")
& (if buffer-file-coding-system
(concat " Coding:"
(symbol-name
(coding-system-get buffer-file-coding-system
'mime-charset))))
& " -*-"
& \n
& \n "(defpackage #:" str
\n "(:nicknames" ("Nickname: " " #:" str) & ")" | '(kill-whole-line -1)
\n "(:use #:CL" ((slime-read-package-name "USEd package: ") " #:" str) ")"
")" \n
\n
(if v1 "(in-package #:") & str & ")" & \n &
\n
_)
(credits: http://www.foldr.org/~michaelw/log/programming/lisp/defpackage-skeleton)
which (modern) template mode could do the same (and how ;)) ?
Cheers
For the record: even another 7 years later I am still very happy with skeletons. Lots of them available over there in my init files: https://github.com/ska2342/ska-init-files/blob/master/dot.emacs.d/init.el
I use yasnippet.
In my emacs I have this:
(require 'yasnippet-bundle)
In my hook for each mode where I want to use snippets (like my c-mode hook, etc), I have this:
(yas/minor-mode-on)
The "static" snippets I use are available, in the directory structure I use, here:
http://cheeso.members.winisp.net/srcview.aspx?dir=emacs&file=snippets.zip
You need to create the bundle .el file mentioned above, once, when any of the snippets change. do it this way:
(require 'yasnippet)
(yas/compile-bundle
; the starting point
"c:/your/path/yasnippet.el"
; the bundle file to generate
"c:/your/path/yasnippet-bundle.el"
; the snippet dir from which to generate the bundle
"c:/your/path/snippets")
That's it!
Then, when I'm in a C# file and type for<TAB>, I get a template with a for loop. And so on.
I also use yasnippet with dynamic snippet templates. A C# code-completion module I wrote calls yas/expand-snippet with a dynamically constructed string that defines the template to expand.
So, you can type
MyType.Method(<COMPLETE>
...where <COMPLETE> is the code-completion key, and the code-completion module does the lookup on the MyType.Method(, then builds a menu of choices, and pops it up. When the user selects a choice from the menu, the code-completion module builds the template, containing fields for each of the arguments for the selected method. Then it calls yas/expand-snippet and that template is injected into the buffer, just as if it had been a static template. In the dynamically-generated template, each argument to the method gets a "typeover" field, and I just fill it in, tabbing through the fields. Pretty nice.
This "dynamic snippet" idea would work with any code-completion engine. You just need a way to map from a method or function signature, like this:
function(int arg1, string arg2, char arg3)
to a yasnippet template definition string, which looks like this:
function(${1:int arg1}, ${2:string arg2}, ${3:char arg3})
And that's a pretty trivial piece of elisp.
I haven't used skeleton mode much, but I use YASnippet while coding in Ruby and C. Its pretty useful, but I suspect skeleton mode is far more powerful.
The emacs wiki lists Yasnippet as a possible replacement for skeleton. The snippets that come with yasnippet are pretty good, but you should really write your own, as the true power lies there.