How emacs take present file as argument to a function automatically? - shell

I am making my own shell command. What is the command that automatically takes the present file as argument of a function when i press enter (just like % in .vimrc file. basically i want that interactive command should invoke automatically when i don't pass any argument as filename while calling the function and automatically takes the present file as the input to the command.

From how I understood your question, you may be looking for the variant of interactive with a lisp form that produces the arguments:
(defun echo-current-buffer-filename (f)
(interactive (list (buffer-file-name)))
(message "Current buffer filename is %s" f))
See the documentation of the interactive function at https://www.gnu.org/software/emacs/manual/html_node/elisp/Using-Interactive.html for more information.

Related

How to make executable File using Gambit

I wrote this Scheme source file on notepad. I have gambit scheme installed.
(define hello-world
(lambda ()
(begin
(write ‘Hello-World)
(newline)
(hello-world))))
I use windows command line. i type in 'gsc hello.scm' in the command line. It spits out a file on my desktop called "hello.o2". I want to see "Hello-World" pop up on my command line. For example, when I compile stuff in c++ it gives me a file called a.exe and I am able to observe it on the command line.
how can I do this with the gambit compiler for scheme?
You can create an executable by adding the -exe compiler switch:
gsc -exe hello.scm
will produce hello.exe . Alternatively you can produce the .o1 (or .o2, etc) file and execute it with:
gsc hello.scm
gsi hello
If you want an executable that will run on its own, you need to do a couple of things to make it work correctly.
#;gsi-script %~f0 %*
;
(define hello-world
(lambda ()
(begin (write `Hello-World) (newline) (hello-world))))
(define (main)
(hello-world))
That first line is for DOS/Windows only. The Unix version of that top line is
;#!/usr/local/bin/gsi-script -:d0
Those lines tell the compiler how to execute the code once its compiled.
Also, you need a main procedure. If you're not passing any parameters, then you can use the form I gave you. If you need to pass parameters, you will need to write the main procedure appropriately, noting that all parameters are passed as strings and may need to be parsed or converted before use.

Emacs Lisp: suppress "Saving file" text while running ELisp file from shell

To start my Emacs Lisp script from shell, I use this command:
emacs --script my-script.el -f my-function
In my script I save 3 buffers to 3 files.
And it's working OK. But when script is running on the shell it prints the text:
Using vacuous schema
Saving file "some-file-to-save"
Wrote "some-file-to-save"
This text prints 3 times. How I can suppress this text?
I don't know offhand how to fix it "properly" in ELisp, but an easy solution would be to just discard output:
emacs --script my-script.el -f my-function > /dev/null
This tells the shell to send all of stdout to /dev/null (which discards all data written to it). Obviously this requires a) an operating system that has /dev/null (i.e. most Unices, including macOS) and b) a shell that doesn't suck (i.e. not cmd.exe).
Identify the function calls that dumps these messages in your script.
Assuming that the first message comes from the function save-buffer which calls the function message (files.el), just override the behavior of message by replacing, in your script, the invocation of save-buffer (or whoever is called) by:
(cl-letf (((symbol-function 'message) #'ignore))
(save-buffer))
Your need to add
(require 'cl-lib)
on top of your script if not already there.

Emacs how to run command in Interactive command line mode in elisp

I am newbie to Emacs.
I want to define a function in elisp to run a command in interactive command line mode (Asynchronously if possible).
my current code is:
(defun ma () ;run maxima batch on the current file
(interactive)
(let*
((fn (buffer-file-name)) (cmd (concat "maxima -b " fn)))
(message "cmd:%s" cmd)
(shell-command cmd)
)
)
this works fine when I do not have break points in the maxima code. When I have break points "break()", I have to interact with the program. The current shell-command function does not work.
I also like the mechanism of "shell-command" function that the screen will automatically split into two and show the programming running info in a second window. If possible, I still want this feature in the code that you can help me with.
Any help would be appreciated.
I want to define a function in elisp to run a command in interactive
command line mode (Asynchronously if possible).
Maybe async-shell-command is what you are looking for do C-h f async-shell-command RET for help on the function.
Use the built in compile function in commint mode.
(defun ma (&optional filename)
(interactive)
(compile (format "maxima -b %s" (or filename (buffer-file-name))) t))
This will open up a new window and will show you the output of the program running. Commint mode means that the compilation process is interactive, you will be able to send input to the program from the compilation buffer.

Reading command-line arguments in MIT-scheme

I am trying to run a scheme program using MIT-scheme (MIT/GNU Scheme running under GNU/Linux, Release 7.7.90.+ || Microcode 15.1 || Runtime 15.7) and I would like to access the command-line arguments.
I have looked in the documentation but I haven't found anything specific.
I have tried command-line, but I get an error message:
;Unbound variable: command-line
Do I have to load some library in order to use command-line, or is there some other function for this?
I have managed to find the following solution.
I have created a file init.scm with the following definitions:
(define command-line-args '())
(define parse-argument-list
(lambda (arg-list)
(set! command-line-args
(if (null? arg-list)
(list)
(cdr arg-list)))))
(set-command-line-parser! "args" parse-argument-list)
In this way, when the command line option --args is found, the function
parse-argument-list is invoked.
I have loaded this file into the mit-scheme interpreter and saved a world image
(init.com) using the procedure disk.save.
I have then written a shell script (bash) that invokes my main Scheme script as follows:
mit-scheme --band "init.com" --interactive --batch-mode --args $* < myscript.scm
Finally, in my main script I can access the command line arguments through the variable
command-line-args
I am not sure whether this is the standard / correct way to do this but at least it works.

Multiple asynchronous shell-commands in Emacs-Dired?

Emacs obviously can handle multiple asynchronous sub-processes, otherwise a multi-language programming environment like org-babel, to give an example, wouldn't be possible.
However, when I'm in Dired and start an asynchronous shell command to view a pdf file (& evince), and then try to do the same on a second pdf file, I get the following message:
"A command is running - kill it? Yes or No?"
Is there a way to run several asynchronous shell commands in parallel, when in Dired?
When you use dired-do-async-shell-command Emacs create a *Async Shell Command* buffer. If you want another async command you need to rename this buffer, for example using M-x rename-uniquely
you could try to change the comportment of dired-do-async-shell-command by advising it:
(defadvice shell-command (after shell-in-new-buffer (command &optional output-buffer error-buffer))
(when (get-buffer "*Async Shell Command*")
(with-current-buffer "*Async Shell Command*"
(rename-uniquely))))
(ad-activate 'shell-command)
note that I really advice the shell-command Emacs command because it's called by dired.
I don't think it's possible with dired-do-async-shell-command, but if you just want to open some file is certain external application I suggest using OpenWith, which allows any number of external processes running.
I've just setup the following which erases the current definition of dired-run-shell-command to pass a dedicated buffer name to shell-command:
(defun dired-run-shell-command (command)
(let ((handler
(find-file-name-handler (directory-file-name default-directory)
'shell-command)))
(if handler (apply handler 'shell-command (list command))
(shell-command command
(generate-new-buffer-name
(concat "*Shell Command Output: '" command "'*")))))
;; Return nil for sake of nconc in dired-bunch-files.
nil)

Resources