To start my emacs lisp script from shell, I use the next command:
emacs --script my-script.el -f my-function
And it's work OK. But when script is running on shell it's print text 'Mark set' many times. How I can remove this text?
Pass NOMSG to push-mark
(Did you write the script yourself? It sounds like you did, but if so then I'm confused that you didn't check the documentation for the mark-related functions you're calling.)
I fix the problem. In my script I use command "beginning-of-buffer" that use function "push-mark". As result it print "Mark set".
So I replace "beginning-of-buffer" by "(goto-char (point-min))" and "Mark set" not print anymore.
P.S. In elisp documentation:
"beginning-of-buffer" - Don't use this command in Lisp programs!
Related
How can I create a macro (for instance LibreOffice calc) that runs a bash script in terminal (for instance xfce4-terminal). An example:
#!/bin/bash
echo "Hello world"
echo "Press any key to close this window"
read
I tried the Shell command in macro editor, but nothing happened. Here is what I did:
Sub testMysql
Shell ("/mnt/save/janos/home/testbashsql",4)
end Sub
It compiles and runs without error, but no output. As a side question: what does "compile" mean in this context, i.e. what happens to the compiled code? where is it stored? Why is there a "compile" button?
Thanks for helping me better understand macros.
Calling the script will execute the script in a shell. To see results, the script should write to a file rather than stdout, because LibreOffice does not display stdout.
To open a terminal instead, call the terminal. This worked on my system.
Shell("xterm")
Regarding the compile button in the LO IDE, I use it to check Basic code for any syntax errors. I am not aware of any compiled stored code. Documentation is at https://help.libreoffice.org/Basic/Compile.
It is possible to start emacs from the shell and tell it to execute a lisp function, e.g.
emacs -f some-lisp-function my_file.py
However, I would like to pass also lisp functions with arguments, like
emacs -f "(goto-line 10)" my_file.py
# --> not working
and in the best of all worlds, pass also more complex lisp code consisting of multiple function calls, like
emacs -f "(goto-line 10) (some-other-func some-arg)" my_file.py
# --> not working
Does somebody know how?
Edit: To clarify this point, I need a way to evaluate the lisp code in the file's own buffer, after opening it.
(Btw. I know that the goto-line problem could be solved differently without using -f but thats just one example for my general problem)
Try emacs my_file.py --eval '(progn (goto-line 10) (some-other-func some-arg))'. Also note that invoking Emacs as emacs +10 my_file.py will open the file at the tenth line.
You have access to the command line that Emacs was invoked with. You can add code to handle your own command line switches. Depending on what you want, this may be cleaner than --eval. See http://www.gnu.org/software/emacs/manual/html_node/elisp/Command_002dLine-Arguments.html and Emacs custom command line argument.
How do I call an emacs lisp function programmatically from an inferior shell?
For instance, I'm in a shell that uses some characters that emacs recognizes and attempts to autoexpand, so I want to run this command (setq comint-input-autoexpand nil) to apply it to the shell I'm in.
I can do this now by entering the text of the command in the shell and running something like eval-region on it but I want my shell to be able to invoke this command itself.
Thanks to the people who responded but it seems my question is unclear. I can accomplish what I want by entering an elisp expression, selecting it, and calling 'eval-region' on it but this requires manual input. What I want is a way to automate this so my shell can send emacs a command to change its own settings.
The "emacsclient" suggestion seems like it's in the right direction but I'm afraid that Windows does not fully support its options and it's unclear that such a command would affect the buffer from which I invoke it since I would do so via an external "shell" command.
What I want is some sort of escape sequence that signals emacs "This elisp expression is for you". I'm guessing there might be a way to open a socket to emacs and send it commands this way but I still have the problem of selecting the buffer to which to apply the command. Again, this is probably more difficult/impossible in Windows, so I will rely on my command bound to a key sequence for now.
It sounds like you are looking for M-x eval-expression, bound by default to M-: (Alt+Colon, i.e. Alt+Shift+semicolon). The expression is evaluated in whatever context you were in when eval-expression was invoked, so if the expression sets a buffer-local variable, it will be set for your current buffer.
You can use emacsclient to do it. You'll need to have started emacs as a server, either with (server-start) in your .emacs or by starting emacs as a background process with --daemon.
You can evaluate elisp code in your shell like this:
emacsclient --eval '(setq comint-input-autoexpand nil)'
I am creating a journal application for personal notes and have the following in my Rakefile:
task :new do
entry_name = "Entries/#{Time.now.to_s.gsub(/[-\ :]+/, '.').gsub(/.0500+/,'')}.md"
`touch #{entry_name}`
`echo "# $(date)" >> #{entry_name}`
end
The last part I would like to include is the opening of the Vim text editor but I am unable to figure out how to open it as if I called it directly from the bash terminal.
I have tried:
vim #{entry_name}
but unfortunately I think both of those open it as a background process.
I have been referencing "6 Ways to Run Shell Commands in Ruby".
As in the article you referenced, `s run the command in a subshell within the current process, but the real problem is that it's trying to take the output from the command run as well, which doesn't play nice with Vim.
You can either:
Use exec to replace the current process with the new one (note that the Ruby/Rake process will end once you've called exec, and nothing after it will run).
Use system to create a subshell like `s, but avoids the problem of trying to grab Vim's stdout. Unlike exec, after Vim terminates, Ruby will continue.
you need to pass the tty as standard input for backspaces etc. to work well in vim:
exec("</dev/tty vim a b")
obviously the backtick (`) didn't work but I was having issues with system/exec from a script.
first I get Vim: Warning: Input is not from a terminal, and then I see ^? when I use backspace.
The general idea is pretty simple, I want to make a script for a certain task, I do it in the shell (any shell), and then I want to copy the commands I have used.
If I copy all the stuff in the window, then I have a lot of stuff to delete and to correct. (and is not easy to copy from shell)
Resume: I want to take all the things I wrote...
Is there an easy way to do this easy task?
Update: Partial solution
In bash, the solution is pretty simple, there is a history command, and there are ports of the idea:
IRB: Tweaking IRB
Cmd: Use PowerShell -> Get-History (or use cygwin)
Another Update:
I found that doskey have a parameter history to do this:
cmd: Doskey /history >> history.cmd
Yes, you can use:
history -w filename.sh
This will save your command history to filename.sh. You may need to edit that to keep just the lines at the end that are part of your command sequence.
NOTE: This is a bash command and will not work with all shells.
script may help here. Typing script will throw you into a new shell and save
all input and output to a file called typescript. When you're done with your interaction,
exit the shell. The file typescript is then amenable to grep'ing. For example, you might
grep for your prompt and save the output to the file. If you're a clumsy typist like me, then you may need to do some cleanup work to remove backspaces. There used to be a program that did thisbut I don't seem to find it right now. Here is one I found on the
'net: http://www.cat.pdx.edu/tutors/files/fixts.cpp
This approach is especially useful if you want to track and post on the web an entire interactive session.