Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;; gkos lib
- ;;
- ;;
- (defmacro for-each-line (&rest body)
- `(save-excursion
- (let (line)
- (goto-char (point-min))
- (while (< (point) (point-max))
- (setq line (buffer-substring-no-properties (progn
- (beginning-of-line)
- (point))
- (progn
- (end-of-line)
- (point))))
- (forward-line 1)
- ,@body))))
- (defmacro awk (&rest body)
- `(for-each-line
- (setq line (split-string line))
- ,@body))
- (defun sprunge-buffer ()
- (interactive)
- (let ((url-request-method "POST")
- (url-request-data (format "sprunge=%s"
- (url-hexify-string
- (buffer-substring-no-properties (point-min) (point-max))))))
- (switch-to-buffer-other-window (url-retrieve-synchronously "http://sprunge.us"))))
- (defun ascii-to-hex (b e)
- "Translate an ascii string to a hex string and copy it to clipboard"
- (interactive "r")
- (save-excursion
- (let ((i b)
- (x-select-enable-clipboard t)
- s)
- (while (< i e)
- (setq s (concat s (format "%x" (get-byte i))))
- (setq i (+ i 1)))
- (kill-new s t)
- (message s))))
- (defun hex-to-ascii (b e)
- "Translate the region from hex to ascii and copy it to clipboard.
- I use that to translate urls in hex and paste it on url bar on my
- browser."
- (interactive "r")
- (let ((i b)
- (x-select-enable-clipboard t)
- s)
- (while (< i e)
- (setq s (concat s (format "%c" (read (concat "#x" (buffer-substring-no-properties i (+ i 2)))))))
- (setq i (+ i 2)))
- (kill-new s t)
- (message (format "%s copied to clipboard" s))))
- (defun reverse-string-region (b e)
- "Reverse a string on region"
- (interactive "r")
- (let ((str (buffer-substring-no-properties b e)))
- (delete-region b e)
- (insert (reverse-string str))))
- (defun reverse-string (str)
- "Reverse a string using nreverse"
- (apply 'string (nreverse (string-to-list str))))
- (defun seq (start end &optional step)
- "Return a list (@start @start+step @start+step*2 ... @end)"
- (let ((l)
- (i end)
- (step (or step 1)))
- (while (> i start)
- (setq i (- i step))
- (setq l (cons i l))
- )
- l)
- )
- (defmacro inc (n &optional step)
- `(setq n (+ n ,(or step 1))))
- (defun bytes-in-region (b e)
- "Count number of bytes on region.
- I use this to calculate lenght of strings while programming. The
- lenght (in characters) is copied to clipboard"
- (interactive "r")
- (let ((i 0)
- (x-select-enable-clipboard t))
- (while (< (+ b i) e)
- (setq i (1+ i)))
- (kill-new (format "%d" i))
- (message (format "%d bytes" i))))
- (provide 'gkos)
Advertisement
Add Comment
Please, Sign In to add comment