Skip to content

Commit

Permalink
Merge pull request magnars#94 from lujun9972/s--aget
Browse files Browse the repository at this point in the history
modify the `s--aget'
  • Loading branch information
magnars committed Apr 29, 2016
2 parents b2436c2 + 44cb8b7 commit 981e0c7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 8 additions & 1 deletion dev/examples.el
Expand Up @@ -309,7 +309,7 @@
(s-presence "foo") => "foo")

(defexamples s-format
;; One with an alist works
;; One with an alist works
(s-format
"help ${name}! I'm ${malady}"
'aget
Expand All @@ -331,6 +331,13 @@
#s(hash-table test equal data ("name" "nic" "malady" "on fire")))
=> "help nic! I'm on fire"

;; Don't have to be string
(s-format "I'm ${name}, ${sex}, ${age} years old"
'aget
'((name . "Nick") (sex . male) (age . 2)))
=> "I'm Nick, male, 2 years old"


;; Replacing case has no effect on s-format
(let ((case-replace t))
(s-format "help ${NAME}!" 'aget '(("NAME" . "Nick"))))
Expand Down
4 changes: 3 additions & 1 deletion s.el
Expand Up @@ -333,7 +333,9 @@ This is a simple wrapper around the built-in `string-match-p'."
(replace-regexp-in-string (regexp-quote old) new s t t))

(defun s--aget (alist key)
(cdr (assoc key alist)))
(let ((result (cdr (assoc-string key alist))))
(when result
(format "%s" result))))

(defun s-replace-all (replacements s)
"REPLACEMENTS is a list of cons-cells. Each `car` is replaced with `cdr` in S."
Expand Down

0 comments on commit 981e0c7

Please sign in to comment.