Configuring Org-Gcal to have subheadings within Spacemacs - emacs

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.

Related

org-mode - no refile targets

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.

New to Emacs. When I type ", \" is automatically inserted

As the title states, I'm relatively new to Emacs. I tried out several starter kits but went with Prelude and changed a lot of things around.
Anyway, I've been getting a good handle on everything...until this morning I was working and I typed double-quotes. Normally Emacs would insert a second double quotes right after ("") due to the auto-completion, but I must have accidentally changed something with a keystroke and now when I type ", I get \"\".
Thoughts?
Thank you.
This seems to be an issue with smartparens which prelude installs by default (see the file prelude-programming.el. This behavior is described in detail on smartparens wiki. To ensure that smartparens is causing problems you can can do C-h k" this would print about the command acutally run when " is pressed, if the command is sp--self-insert-command then the following should work
Paste this (setq sp-autoescape-string-quote nil) to your *scratch* buffer, go to the closing parenthesis and do C-xC-e, this will disable the behavior for current emacs session.
To disable the behavior for all future emacs session, assuming that you are using prelude, you will need to add the following to your personal config (basically some file inside /path/to/prelude/personal/).
(setq sp-autoescape-string-quote nil)
This will disable the auto-escaping of the string quotes, completely. If you like this behavior and do not want to disable it completely you can do what #steckerhalter suggests C-q" will insert just one parenthesis.
If the above does not solve the issue then try providing following info in your question which may help us debug the issue,
1) The list minor modes active (this can be obtained by doing C-hm).
2) Output of C-hk"
Hope that helps
this sounds a lot like smartparens (https://github.com/Fuco1/smartparens) which is included in Prelude. usually when you are inside "" then it will escape the quotes:
"hahah \"\" bah"
if you want to get a normal " inside quotes you have to use C-q " or disable smartparens with M-x smartparens-mode
If, as you say in a comment, " is bound to self-insert-command, then when you type " what happens is that a (single, unescaped) " character is inserted.
However, I suspect you have some mode turned on that does something additional whenever a " char is inserted. You mention automatic insertion of a second ", for example. That kind of behavior comes from a mode such as is provided by library smart-parens or electric-pair.
And you mention Prelude.
To find out what part of your init file (~/.emacs) is causing the behavior you see, bisect your init file recursively (first comment-out half, to see which half is responsible, then 3/4, to see which quarter is responsible,...). Then, if you still have a question about the responsible code, ask here, providing that info.
When you describe your problem here, it is important to be specific: what Emacs version, what mode(s), what libraries have you loaded,... Whatever might be pertinent. But first narrow down the problem by bisecting your init file to find the culprit.

Emacs lisp highlighting

I have wrote simple macro to define interactive function and bind it to key at same time
(That what my previous question related)
The only thing, that annoy me, that it looks ugly without highlighting.
It called such way:
(define-and-bind-command foo "C-x £" (message "Hello world"))
I want define-and-bind-command and foo be highlighted.
Well, to get define-and-bind-command highlighted, I can use wrapper around defmacro,
altho is not so pretty, and I have no idea about foo.
I know it is possible, because argument of require is highlighted with const face.
Or, probably, I am inventing wheel, and there is an another lisp mode with more
advanced highlighting?
highlighting the 'define-and-bind-command' can be achieved very easily using 'font-lock-add-keywords', usage would be
(defun my-elisp-mode-keywords()
(font-lock-add-keywords nil
'(
("\\<\\(define-and-bind-command\\)" . 'font-lock-keyword-face)
)
)
)
Of course you could change the 'font-lock-keyword-face' to any face of your liking or create and use your own face. You can find the name for a face already used very easy by moving the point (cursor) over the font-locked part of text and entering 'describe-face' followed by a return.
Edit2: Oh and of course you need to hook that defun to some hook, for elisp mode that would be:
(add-hook 'emacs-lisp-mode-hook 'my-elisp-mode-keywords)
Highlighting the foo part can be done using a regexp.
Unfortunately I can not yet help you with that part because I'm not sure how to match a regexp containing the 'define-and-bind-command' but highlighting only the word after.
Edit: unless you want to highlight both the 'define-and-bind-command' and the foo part in the same face, then it should be very easy. But I guess you want them to have different faces?
Edit3: Corrected my code, stackoverflow ate some braces before...
Edit4: Okay, I have a solution for matching the second part only, I have not tested it extensively but it seems to work. I have allowed for foo to contains any character but a space (and newline I think), I guess one could restrict that event futher to a-zA-z0-9 and "-", so feel free to change that to your liking. The Code responsible for matching only the foo part is
("\\bdefine-and-bind-command\s\\([^\s]*\\)" 1 'font-lock-function-name-face t)
Insert that in the line after the other font-lock keyword in the above function and you're good to go. The regexp matches 'define-and-bind-command' which must begin a word (that's the \b for) followed by a space and then it returns (font-locks) everything followed until a space exists.
Hope this helps!
font-lock-add-keywords can take a symbol, the mode to which to apply the new keywords. So you could do
(font-lock-add-keywords
'emacs-lisp-mode
'(("\\<\\(define-and-bind-command\\)" . 'font-lock-keyword-face)))
The disadvantage compared to using a function and a hook is that this doesn't work for derived modes; that is, if you have a mode which is derived from emacs-lisp-mode, it will not inherit these keywords.

minibuffer input: word completion with custom dictionary

I am trying to accept user input for a command-line utility in emacs. I've got a handful of words that I can use in this command-line (something like the possible target list of a make invocation), and I want to be able to auto-complete words that I know about, allow user to input more than one entry in my dictionary, and also allow the user to write things not in my dictionary. Some library that allows word completion in minibuffer using a custom dictionary would be just the thing.
I do not require a full solution, but a few pointers on where to start looking would be much appreciated. Also, I'd rather avoid using intrusive libraries such as icicles or ido if at all possible - I don't want the users of this package to be limited in how they configure the rest of their setup.
My best solution so far is to use completing-read multiple times for each target until the user enters the empty string.
Solution
event_jr's answer below did the trick. The final code I've used looks like:
(require 'crm)
(let ((crm-separator " ")
(crm-local-completion-map (copy-keymap crm-local-completion-map)))
(define-key crm-local-completion-map " " 'self-insert-command)
(completing-read-multiple "prompt: " '("foo" "foobar" "baz"))))
How about this:
(completing-read-multiple ": " '("foo" "foo2" "foobar"))

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.