My emacs functions
Table of Contents
1. My emacs functions
These are some elisp functions I wrote.
1.1. cHelper
cHelper is a little project of mine. Until now it can only create .h files from .c files in some cases :). It has a little readme. cHelper
1.2. PC status
This is a function that displays a conky like minibuffer which contains some info about your battery status, time and so on.
(defun read-file (path)
"reads a file and returns its content."
(with-temp-buffer
(insert-file-contents path)
(buffer-string)))
(defun show-conky ()
"prints some information about the current battery status, volume and so on"
(interactive)
(setq conky (shell-command-to-string "date"))
(let ((cmd (shell-command-to-string "amixer get Master")))
(string-match "\[[0-9]*\%\]" cmd)
(setq conky (concat conky "Sound: " (match-string 0 cmd) " "))
(if (numberp (string-match "\\[on\\]" cmd))
(setq conky (concat conky "on\n"))
(setq conky (concat conky "off\n"))))
(setq conky (concat conky "Battery: "
(comment-string-strip (read-file "/sys/class/power_supply/BAT1/capacity") t t) "% "))
(setq conky (concat conky (read-file "/sys/class/power_supply/BAT1/status")))
(message "%s" conky))
1.3. Backup
This is a little backup script I wrote. You should adjust /home/user to your home directory's path.
(defun create-backup-archive (destination)
"DESTINATION is a device (e.g. /dev/sdb1) where the tar.gz file should be placed
it has the name bkp-Y-m-d.tar.gz.gpg"
(let* ((archive-name (format-time-string "bkp-%Y-%m-%d.tar.gz"))
(tar-cmd (concat "tar cfz /tmp/" archive-name " /home/user")))
(progn (shell-command tar-cmd)
(epa-encrypt-file (concat "/tmp/" archive-name) nil)
(let ((default-directory "/sudo::/"))
(progn (shell-command (concat "mount " destination " /mnt"))
; I rather wanted to use (copy-file) but it gave me a permission denied error
; this is my workaround.
(shell-command (concat "mv /tmp/" archive-name ".gpg /mnt/" archive-name ".gpg"))
(shell-command "umount /mnt"))))))