Unable to understand Emacs Lisp string

Line

function info() { emacs -eval "(progn (setq Man-notify-method 'bully) (info \"$1\"))" } 

I know from the manuals that

Progn

progn is a special form in source C code. "

SETQ

setq is a special form in source C code '. (setq SYM VAL SYM VAL ...)

Set each SYM to its VAL value. SYM characters are variables; They are literal (not graded). VAL values โ€‹โ€‹are expressions; they are appreciated. Thus, (setq x (1 + y)) sets x' to the value of (1 + y)'. the second VAL is not calculated until the first SYM is installed and so on; each VAL can use the new value of the variables previously set in the form of setq'. The return value of the setq'. The return value of the setq ', is the value of the last VAL.

$ 1 seems to refer to the first parameter after the man command that the user gives.

'bully seems to be a random variable.

Man-notify-method is represented by an action function that is run when the man command is executed.

-eval seems to be an evalutian statemant that tells Emacs to execute the statement that follows it.

However, I'm not quite sure about the function.

I need to understand this function, since I want to bind the bash code to the action of a human function. The Man-notify-method seems to have this action function, at least in Emacs.

How do you understand the Emacs Lisp line?

+4
source share
2 answers

PROGN simply evaluates the expressions in order, returning the return value of the latter.

SETQ is the main assignment operator.

INFO is included in the emacs information browser.

So what does this mean, first assign the 'bully character to the Man-notify-method variable, and then go into the info browser. 'bully is most likely the name of the function, and Man-notify-method place where the information browser looks for the function to call some kind of notification (warning: I'm just guessing here).

I assume that you will need to define your own function that calls your shell command as follows:

 (defun my-cmd () (call-process ; Look up the syntax in the emacs lisp manual )) 

Then assign your character to the Man-notify-method :

 (setq Man-notify-method 'my-cmd) 
+6
source

The code you submitted is a combination of a shell script and elisp.

 function info() { emacs -eval "(progn (setq Man-notify-method 'bully) (info \"$1\"))" } 

Defines a shell script called info . It takes 1 parameter called $1 . When you call this function (for example, from another shell script), the value of the argument is replaced with $1 , and it runs the commands specified in the sequence. So, if you call it like this:

 info("something") 

The shell will execute the following command:

 emacs -eval "(progn (setq Man-notify-method 'bully) (info \"something\"))" 

This invokes the emacs executable with two -eval arguments and a command line that contains embedded escaped quotes. This calls emacs to invoke the following elisp code:

 (progn (setq Man-notify-method 'bully) (info "something")) 

progn is a special form. Special forms evaluate their arguments differently than regular function calls. You can find documentation for progn in chapter 10.1 of the GNU Emacs Lisp Reference Manual . progn is a simple construct for executing a sequence of instructions in order. The reason you might need to do this is when you want to execute several statements, but the context you are in expects only one statement.

For example, an if takes 3 (or more) arguments: a condition for evaluating, an expression for evaluating if true, and an expression for evaluating if false. If more than three arguments are provided, subsequent arguments are part of the else branch. If you want to use more than one statement in a true branch, you should use progn :

 (if condition (progn first-statement-if-true second-statement-if-true) first-statement-if-false second-statement-if-false ) 

In this case, if condition true, then first-statement-if-true and second-statement-if-true will be evaluated. Otherwise, first-statement-if-false and second-statement-if-false will be evaluated.

That way, your code will simply evaluate the two statements (setq Man-notify-method 'bully) and (info "something") in order.

setq is another special form. See chapter 11.8 for your documentation. It simply sets the variable named by the first parameter, the value of the second parameter. The first parameter is not evaluated - it is taken literally.

A value preceded by a single quote (for example, 'bully ) is not evaluated. For more information on citation, see chapter 9.3 . Therefore (setq Man-notify-method) sets a variable named Man-notify-method to the bully literal token (which is a data type called a character that is different from the string "bully" ).

I canโ€™t find the documentation for the info function on the Internet, you can get help for any given function in emacs by typing Ch f function-name . So, typing Ch f info , I got the following:

  info is an interactive autoloaded Lisp function in `info '.
 [Arg list not available until function definition is loaded.]

 Enter Info, the documentation browser.
 Optional argument FILE specifies the file to examine;
 the default is the top-level directory of Info.
 Called from a program, FILE may specify an Info node of the form
 `(FILENAME) NODENAME '.

 In interactive use, a prefix argument directs this command
 to read a file name from the minibuffer.

 The search path for Info files is in the variable `Info-directory-list '.
 The top-level Info directory is made by combining all the files named `dir '
 in all the directories in that path. 

An online reference is very useful, and emacs online help is also needed. If you donโ€™t understand what a particular function does, just Ch f it.

+12
source

All Articles