Two more videos to finish up the rot13 project.
The first video covers about prefix arguments. The idea is when
calling an Emacs function interactively, you can specify a numeric
argument either by typing
C-u # where
# is a single digit or
## is an integer which can be positive, negative, single
or multiple digits. You then type the key for your command or invoke
it with its full name
M-x. This passes the numeric parameter to the
In the function, we add a parameter to the
(interactive) form -
(interactive "P") which says that the parameter to our
function will be that number we passed as a prefix argument or nil if
there was no prefix argument.
We use the prefix argument to determine how much to rotate our text. If we don't pass a parameter, we just do a rot13 but if we do, we rotate that amount.
The second video shows how we can use see if there's an active region and if so, run our rotate function on the text in that region. If not, rotate the previous word.
Here are the key Emacs features we instroduce.
|a built in variable which is true if you've set the mark
|returns an integer representation of where the mark is set
|returns an integer representation of where the cursor is
|returns text from the buffer
Notes from previous videos:
A viewer pointed out that the Emacs if statement can actually have multiple forms to its false part.
will print "Hello" if
condition is true and "Goodbye" if it's fales.
Now, if we have multiple forms int he false part:
then while it will still print "Hello" if
condition is true, it will
print both "Goodbye" and "World" if it is false.
I didn't know that and appreciated the comment so that I could learn something new.
Here's the code and video links.
Once again, the code is up online:
The rot13 code will be in the file rot13.el.