how to jump to the next argument of function and edit it quickly in doom emacs - emacs

When I complete the function, what if I jump to the next parameter of the function?
For example, when writing golang, I type fmt.f and enter to get the snapshot:
fmt.Printf(format string, a . . interface{})
and then I edit the first argument to
fmt.Printf("hello %s", a . .interface{})
now I want to quickly jump to the next parameter (a . . inteface) and edit it like c-j in neovim coc do, how do I do this? thinks for your reply!

Related

Unable to change a text property for an org-mode link

I have the following at the top of an org-mode buffer:
[[aaa][bbb]]
(add-text-properties 1 13 '(help-echo "zzz"))
When I execute the list expression on the second line and hover the mouse of the link, I still get the help echo "LINK: aaa", not the expected "zzz".
UPDATE: I used edebug-trace and found that org-mode runs its code after I run mine and reverts the property back. I will have to use advising function, or, is there another way?

Create inactive timestamp keyboard shortcut not working

So, according to the Emacs manual, you can create inactive timestamps of the form [1970-01-01 Thu] by hitting C-c !.
However, doing so will result in my minibuffer displaying C-c !- waiting for further input. Hitting space or return doesn't work and just results in an error saying C-c !-RET isn't a valid command.
What exactly happened here? Is the command simply not defined by default? I'm fairly certain I don't have anything defined that globally overrides this, but I could be wrong.
If you type C-c ! <f1> you'll see a list of all keybindings that start with C-c !. Does that help?
I don't think there's a timestamp function bound to C-c ! by default, but there are plenty of results if you Google "Emacs timestamp".

Accessing command's argument in auto-completion function in zsh

I wish to create a custom command which has it's first argument as a regex & pressing TAB after typing regex will open a auto-complete menu with all the files matching the pattern.
if I name my command vimf (meaning vim find) and write the auto-complete function like:
#compdef vimf
_arguments "1: :_files -g \"**/*.conf\""\
In the above auto-complete function, typing $vimf , lists all the files ending with .conf in the auto-completion menu. Now, I want this part .conf to be taken from the first argument of the command. So, if I type something like: vimf *.pp, I want it to search only files ending with *.pp.
How do I make that possible? How can I use the arguments of a command while writing auto-complete functions?
To do this you need to use the words array which is set to the content of the command line.
From this, you retrieve the file type by accessing the good index, and troncate the prefix. (this is done by #compdef vimf)
Here is the result:
#compdef vimf
_arguments "1: :_files -g \"**/*.${words[2]##*.}\""\
&& return 0
I tried it on my terminal, it works, but of course can take long time to perform if your do this by the root. Enjoy :)

How do I use defjump in emacs lisp to jump to a function in a file?

What I'd like that to do, is when I'm on a line of source such as: foo
And I hit a "jump" key, it should match href="foo.html" and open the file c:/project/root/templates/foo.html.
I've found jump.el (package 'jump' in emacs 24) and am trying to get defjump to work:
(require 'jump)
(defjump
'my-follow-ref
'(("href=\"\\1\"" . "templates/\\1"))
"c:/project/root/"
"Follow a logical link from one part of the source to another.")
My code is based on the example in the help, but I'm getting stuck on a pretty basic emacs lisp error:
mapcar: Wrong type argument: listp, quote
What am I doing wrong?
There is no jump.el in the emacs 24 source tree, and google is no help, but, I guess, your problem is unnecessary quoting: defjump is probably a macro.
Chances are this will work:
(defjump
my-follow-ref
(("href=\"\\1\"" . "templates/\\1"))
"c:/project/root/"
"Follow a logical link from one part of the source to another.")

How can I modify emacs' Search and Replace to perform a more complicated task?

total Emacs noob here. So right now I'm working on a fairly big LaTeX project in Emacs in which there are couple of places where I need to index some words, using the makeidx package. Because I also wanted indexed words to be bold, I created my own command \ind{} which would make the argument go bold and indexed. But right now I'm dissatisifed with this command so I'd like to change every instance of \ind{whatever} in my text by \textbf{whatever}\index{whatever by default}.
The thing is I know exactly what I want :
Go through the text, look for any instance of \ind{ and replace by \textbf{ using search-and-replace
Save the argument of \ind ("whatever" in this case) in memory
Ask me the user what should the argument of \index be. By default (by striking enter), it should be the first argument, but I can also change my mind and enter something different ("whatever by default" in this case). If there's no input (only a space " " for example) stop the program.
Write down \index{, the new argument and }.
Go to next occurance in the text.
But, alas!, I know not how to achieve this, so I need someone's help. If it should take too much time to explain how to do such a thing, would you please send me some tutorial about writing my own functions?
I hope I'm being clear, and thanks for your patience!
This approach seems vaguely unorthodox to me, but it works and seems sufficient for a one-off job...
In the replacement text for replace-regexp and query-replace-regexp (C-M-%), one newer escape sequence is \,(...), where ... can be any Lisp expression. There's a Lisp function read-from-minibuffer which reads arbitrary text typed by the user, with an optional default. Therefore:
C-M-%: Start query-replace-regexp.
\\ind{\([^}]+?\)}: The pattern to search for.
\\textbf{\1}\\index{\,(read-from-minibuffer "index content? " \1)}: The replacement text. The user will be prompted for the text to put in the braces following the \index{} element, using the original text between the braces following the \ind{} element as a default.
Note that when using query-replace-regexp, you'll have to confirm each choice by typing y after each. Use M-x replace-regexp if you want to avoid this step.
Vlad give you the LaTeX answer to your problem. An Emacs solution is the key-macro: start with
C-x (
to define a new macro, then do one step of your change, say:
C-s \ind{
<left>ex
Then copy and paste the argument in the \textbf macro... You have to be careful to move in a way that will be repeatable. Once the standard modification is done, you let the cursor after the whatever by default and end the definition by
C-x )
now C-x e will call the macro you just define, letting your cursor at the correct place to change the part you want to change You can also repeat the e to call the macro several time at once.
Why not just redefine the \ind so that it can get an optional argument?
For example:
\newcommand{\ind}[2][]{%
\def\first{#1}%
\ifx\first\empty
\textbf{#2}\index{#2}%
\else
\textbf{#2}\index{#1}%
\fi
}
This way you can use \ind{whatever} or \ind[whatever-else]{whatever}.