parent nodes: Lisp | PracticingEvaluation
Practicar evaluar expresiones para aprender a usarlasBesides being used for practicing evaluation, the functions shown in
the next few sections are important in their own right. A study of
these functions makes clear the distinction between buffers and files,
how to switch to a buffer, and how to determine a location within it.
How to Evaluate
Se evalúa todo lo que sea una función
Al escribir texto, mover el cursor o hacer scroll se está evaluando una expresión cuyo primer argumento es una función
Al escribir texto plano se llama a la función: self-insert-command que inserta el carácter tecleado
Otra forma de evaluar es ponerse al final de una lista y pulsar C-x C-e
Hay otras formas que veremos más adelante
2.1 Buffer Names
`(buffer-name)' is the same as the name of the file to which it refers
`(buffer-file-name)' is the full path-name of the file.
A file and a buffer are two different entities.
File está fijo en el disco duro y perdura hasta que se borra el fichero
Buffer está en el emacs y se perderá al cerrar emacs o matar el buffer
En el lenguaje humano se suele confundir file y buffer de hecho decimos que estamos editando un archivo en lugar de decir que estamos editando un buffer que pronto guardaremos y se convertirá en un archivo. Programando hay que se más específico ya que el emacs no puede distinguir las dos palabras según el contexto.
Not all buffers are associated with files. For example, a `scratch' buffer does not visit any file. So if you evaluate `(buffer-file-name)' in the `scratch' buffer you'll get `nil' meaning 'no file'
2.2 Getting Buffers
The `buffer-name' function returns the name of the buffer;
The `current-buffer' function returns the buffer itself
There is a slight complication: if you evaluate `current-buffer' in an expression on its own, what
you see is a printed representation of the name of the buffer without the contents of the buffer. (current-buffer)
#<buffer *info*>
La notación especial #<buffer indica que está devolviendo el buffer entero y no sólo su nombre.
You cannot type a number or symbol into the printed representation of a buffer: the only way to get a buffer itself is with a function such as `current-buffer'.
`other-buffer'. This returns the most recently selected buffer other than the one you are in currently
by default, if the buffer from which you just switched is visible to you in another window, `other-buffer' will choose the most recent buffer that you cannot see; this is a subtlety that I often forget.
2.3 Switching Buffers
The `other-buffer' function provides a buffer when it is used as an argument to a function that requires one. We can see this by using `other-buffer' and `switch-to-buffer' to switch to a different buffer.
(switch-to-buffer (other-buffer))
2.4 Buffer Size and the Location of Point
2.5 Exercise