Emacs functions
Since emacs is my editor of choice, I've written some general elisp functions,
which are very simple, but sometimes useful (especially for fast hacking).
You may want to change for example the mailaddress.
Usage
Put the functions which use want to use in your .emacs file and save it. Then
you can call the functions via
Alt-X
function-name
where function-name is the name of the function you want to call.
Please note that the make-functions, inserts text in the current buffer.
Test with an empty buffer first. You can use these functions to make your own
make-a-nice-language yourself.
Here are the functions.
reload-file
Reloads the current file
(defun reload-file ()
(interactive)
(find-file (buffer-name))
)
editemacs
Fetch the .emacs file for editing.
(defun editemacs ()
(interactive)
(find-file "~/.emacs"))
After changes, you can evaluate the buffer with
Alt-X
eval-buffer
strip-html
Strips some HTML-code.
(defun strip-html ()
(interactive)
(goto-char 1)
(replace-string "<" "<")
(goto-char 1)
(replace-string ">" ">")
(goto-char 1)
(replace-string "&" "&")
(goto-char 1)
(replace-string """ "\"")
(goto-char 1)
(replace-regexp "</*B>" "")
)
make-html-page
A very simple HTML-template, which I sometimes use for creating new
web pages on my this site.
(defun make-html-page ()
(interactive)
(goto-line 1)
(insert "<html><head>\n")
(insert "<script language=\"JavaScript\">\n\n\n</script>\n")
(insert "<title>\n</title></head>\n")
(insert "<body bgcolor=\"#ffffff\">\n")
(insert "<form method=\"post\" action=\"\">\n")
(insert "\n")
(insert "<input type=\"submit\" name=\"submit\" value=\"ok\">\n")
(insert "<input type=\"reset\" name=\"reset\" value=\"reset\">\n")
(insert "</form>\n")
(insert "\n")
(insert "<hr noshade>\n")
(insert "Back to my <a href=\"/\">homepage</a><br>\n")
(insert "<address>created by Hakan Kjellerstrand ")
(insert "<a href=\"mailto:hakank\@bonetmail.com\">hakank@bonetmail.com</a>\n")
(insert "</address>\n")
(insert "</body>\n")
(insert "</html>\n")
)
un-mime
For mail files etc where the swedish national characters are MIME encoded.
Note very complete.
(defun un-mime ()
(interactive)
(goto-char 1)
(replace-string "=E5" "å")
(goto-char 1)
(replace-string "=E4" "ä")
(goto-char 1)
(replace-string "=F6" "ö")
(goto-char 1)
(replace-string "=C5" "Å")
(goto-char 1)
(replace-string "=C4" "Ä")
(goto-char 1)
(replace-string "=D6" "Ö")
(goto-char 1)
(replace-string "=3D" "=")
)
make-java
Simple Java code template, used for fast hacks.
(defun make-java ()
(interactive)
(goto-line 1)
(insert "/**\n")
(insert " *\n")
(insert " * ")
(insert (current-time-string))
(insert "/hakank@bonetmail.com\n")
(insert " *\n")
(insert " *\n")
(insert " */\n")
(insert "import java.io.*;\n");
(insert "import java.util.*;\n");
(insert "import java.text.*;\n\n");
(insert "public class ");
(insert (file-name-sans-extension (buffer-name)) " {\n")
(insert " public static void main(String args[]) {\n")
(insert "\n\n")
(insert " }\n")
(insert "}\n")
(insert "\n")
(insert "// Local variables:\n")
(insert "// compile-command: \"javac " (buffer-name))
(insert " && java " (file-name-sans-extension (buffer-name)) "\"\n")
(insert "// End: \n")
(java-mode)
)
make-perl
For small and not so small Perl hacks.
(defun make-perl ()
(interactive)
(goto-line 1)
(insert "#!/usr/bin/perl -w\n")
(insert "# \n")
(insert "# ")
(insert (current-time-string))
(insert "/hakank@bonetmail.com\n")
(insert "# \n")
(insert "# \n")
(insert "# \n")
(insert "$|=1;\n")
(insert "use strict;\n")
(insert "\n\n\n")
(insert "# Local variables:\n")
(insert "# compile-command: \"perl " (buffer-name) "\"\n")
(insert "# End: \n")
(goto-line 11)
(cperl-mode)
)
Note: The "Local variables" in make-java and make-perl is to
be used with the compile command. I.e.
Alt-X
compile
Then the line after "Local variables:" (for example perl test.pl will
be at the "Compile command:" line. Then press Enter to run the
program.
Bug(?): It seems that the first time you create the file, you must close the
buffer and fetch the file again.
Another way of setting the compile command is the following line in .emacs:
(set-default 'compile-command "make")
Back to my homepage
created by Hakan Kjellerstrand hakank@bonetmail.com