reddit / emacs
HOWTO - Open at end of document?
kk19010323 · 2022-06-19 00:44
In vim i could -
Launch a document with a macro
`$ vim somefile.ext +"norm @a"`
---
Send keypresses to the editor (goes to the end of doc, creates a line and gets in insert mode.
`$ vim -c "norm Go"`
1. How do i replicate the same in emacs or maybe improve?
2. What would the command be when launching with emacsclient?
prismavoid08 · 2022-06-19 01:19
If I'm understanding you right, you want to open a file, and then open a new line at the end?
You can execute a function when opening emacs with the `-f` argument, so you can use:
`emacs <file> -f end-of-buffer -f newline`
If you are using evil mode and want to also switch to insert mode you can add an extra `-f evil-insert` at the end or just do:
`emacs <file> -f end-of-buffer -f evil-open-below`
I'm not sure of a way to do this with emacsclient, but there may be something I don't know of.
unixbhaskar · 2022-06-19 02:45
>emacs <file> -f end-of-buffer -f newline
It does work.
1) Open the specified file
2) Put the cursor at the bottom of the file, beginning of a blank line.
diamondnbond · 2022-06-19 07:04
afaik emacsclient with emacs running as a daemon can accomplish alot of what you mention.
kk19010323 · 2022-06-19 07:14
The question is how?
kk19010323 · 2022-06-19 07:56
How do I find the lisp functions being executed at keypresses?
Say I press - SPC b i
I there a way for me to know what the name of that lisp function is?
bhrgunatha · 2022-06-19 08:08
`describe-key` does that. By default it's bound to `C-h k`.
So `M-x describe-key` or `C-h k` - then press the key combination you want to query.
ir210 · 2022-06-19 08:10
Assuming you are using spacemacs: SPC h d k
diamondnbond · 2022-06-19 08:15
something like this:
```
emacsclient -e '(cmd)'
```
kk19010323 · 2022-06-19 08:47
```
[foo@foo: ~]$ emacsclient -e ~/org/org.org -f lisp-function -f lisp-function
emacsclient: error accessing server file "lisp-function"
```
Evil_Yves · 2022-06-19 08:59
The -e for emacsclient won't work for your use-case, but if you take a look at the man page of emacsclient you can see that you can open the file at a given line & column like so:
```
$ emacsclient -n -c +999 org.org
```
Meaning that you create a new frame (-c) do not wait for the frame to finish (-n) such it does not block the terminal and +999 indecates that you start at line 999, if the line does not exist (because the file is shorter, you start at the end of the buffer.
If you choose a large enough number you should be fine.
E3D3redit · 2022-06-19 09:59
`describe-key-briefly` ( Ctrl-h c) is less intrusive.
dotancohen · 2022-06-19 10:11
I'm not OP, but is there a way to add this to a modeline (VIM term, it means a line of code inside the file that affects the editor for that file only)?
Most of my Org file I want to be opened from the top, buy my `daily.org` file I would like to be opened from the bottom.
Bonus points if it can add a `* YYYY-MM-DD` heading to the end of the file if it does not already exist in the file.
TheGramm · 2022-06-19 22:58
Yes! You can use local variables and the keyword eval to evaluate end of buffer, you can also evaluate an insert command to enter arbitrary text. Just google 'local variables emacs' to get to the info page!
dotancohen · 2022-06-20 05:35
Perfect, thank you, I'm googling that now!
theMachine0094 · 2022-06-22 00:07
I do a ```(goto-char (point-max))``` inside my find-file-hook. In my case I only do this for certain file types by checking inside the hook.