Skip to content

Instantly share code, notes, and snippets.

@khaije1
Created July 12, 2012 17:57
Show Gist options
  • Save khaije1/3099675 to your computer and use it in GitHub Desktop.
Save khaije1/3099675 to your computer and use it in GitHub Desktop.
fun w/ elisp
;intern is a built-in function in `C source code'.
;|
;|(intern STRING &optional OBARRAY)
;|
;|Return the canonical symbol whose name is STRING.
;|If there is none, one is created by this function and returned.
;|A second optional argument specifies the obarray to use;
;|it defaults to the value of `obarray'.
;#DEMO: reflection in elisp
;#DEMO: create variable named after the contents, then assign contents to new variable
(defun reflect-value-to-symbol (value)
"assign value to symbol 'value, then return symbol"
(interactive "s")
(if (stringp value)
(let ((tmp value))
(set (intern value) (format "<%s>" value))
(intern value))))
;test
(let
((anon-symbol (reflect-value-to-symbol "test-var")))
(concat "the value of " (symbol-name anon-symbol) " is " (eval anon-symbol)))
;#OUTPUT: ==> "the value of test-var is <test-var>"
;;;
;;; region-md5-to-kill-ring -
;;; generate a distinct charcode from region and insert into paste (aka kill) ring
;;
(defun region-md5-to-kill-ring
;function docstring (optional)
"generate a largely distinct charcode from region and inserts this data into paste (aka kill ring)"
(;input variables list
length ;the length of the returned hash, defaults to 0 or 'not truncated'
)
(interactive argument-passing-info ;optional
)
(;function body
;sanitize inputs, apply defaults
(if
(not (bound-and-true-p length))
;then
(setq length 6)
)
;work
(setq input
(buffer--substring (region-beginning) (region-end))
)
(if
(= length 0)
(;then
(setq outcome
(substring
(md5 input)
(;else
0 length
;outcome
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment