Back
replace (clj)
(source)function
(replace smap)
(replace smap coll)
Given a map of replacement pairs and a vector/collection, returns a
vector/seq with any elements = a key in smap replaced with the
corresponding val in smap. Returns a transducer when no collection
is provided.
Examples
hraberg/deuce
(ns deuce.emacs.fileio
(:use [deuce.emacs-lisp :only (defun defvar) :as el])
(:require [clojure.core :as c]
[clojure.string :as s]
[clojure.java.io :as io]
[deuce.emacs.buffer :as buffer]
[deuce.emacs.data :as data]
[deuce.emacs.eval :as eval]
[deuce.emacs.editfns :as editfns])
(:import [java.nio.file Files LinkOption
NoSuchFileException]
[deuce.emacs.data Buffer BufferText])
(:refer-clojure :exclude []))
For technical reasons, this function can return correct but
non-intuitive results for the root directory; for instance,
(expand-file-name \"..\" \"/\") returns \"/..\". For this reason, use
(directory-file-name (file-name-directory dirname)) to traverse a
filesystem tree, not (expand-file-name \"..\" dirname)."
(el/check-type 'stringp name)
(let [directory (or default-directory (data/symbol-value 'default-directory))]
(if-let [resource (io/resource (str (file-name-as-directory directory) name))]
(.getPath resource)
(let [home (file-name-as-directory (System/getProperty "user.home"))
file (io/file (s/replace name #"^~" home))
file (if (.isAbsolute file)
file
(io/file directory name))]
(if-not (.exists file) ;; Assume its classpath relative dir.
(str (file-name-as-directory directory) name)
(.getCanonicalPath file))))))
(defun insert-file-contents (filename &optional visit beg end replace)
"Insert contents of file FILENAME after point.
Returns list of absolute file name and number of characters inserted.
If second argument VISIT is non-nil, the buffer's visited filename and
last save file modtime are set, and it is marked unmodified. If
visiting and the file does not exist, visiting is completed before the
error is signaled.
If optional fifth argument REPLACE is non-nil, replace the current
buffer contents (in the accessible portion) with the file contents.
This is better than simply deleting and inserting the whole thing
because (1) it preserves some marker positions and (2) it puts less data
in the undo list. When REPLACE is non-nil, the second return value is
the number of characters that replace previous buffer contents.
If `/~' appears, all of FILENAME through that `/' is discarded.
If `//' appears, everything up to and including the first of
those `/' is discarded."
(let [filename (-> filename
(s/replace #".+(~/.+)" "$1")
(s/replace #".+/(/.+)" "$1"))
vars (re-seq #"\$(\w+|\{.+\})" filename)]
(reduce #(s/replace %1 (first %2) (System/getenv (second %2))) filename vars)))
hraberg/deuce
(ns deuce.emacs.casefiddle
(:use [deuce.emacs-lisp :only (defun defvar)])
(:require [clojure.core :as c]
[clojure.string :as s])
(:refer-clojure :exclude []))
(defun upcase-initials (obj)
"Convert the initial of each word in the argument to upper case.
Do not change the other letters of each word.
The argument may be a character or string. The result has the same type.
The argument object is not altered--the value is a copy."
(s/replace obj #"\w+" #(apply str (s/upper-case (first %)) (rest %))))
hraberg/deuce
(ns deuce.emacs.coding
(:use [deuce.emacs-lisp :only (defun defvar) :as el])
(:require [clojure.core :as c]
[deuce.emacs.alloc :as alloc]
[deuce.emacs.charset :as charset]
[deuce.emacs.fns :as fns]
[deuce.emacs-lisp.globals :as globals])
(:refer-clojure :exclude []))
Optional 4th arguments DESTINATION specifies where the decoded text goes.
If nil, the region between START and END is replaced by the decoded text.
If buffer, the decoded text is inserted in that buffer after point (point
does not move).
In those cases, the length of the decoded text is returned.
If DESTINATION is t, the decoded text is returned.
Optional 4th arguments DESTINATION specifies where the encoded text goes.
If nil, the region between START and END is replace by the encoded text.
If buffer, the encoded text is inserted in that buffer after point (point
does not move).
In those cases, the length of the encoded text is returned.
If DESTINATION is t, the encoded text is returned.
hraberg/deuce
(ns deuce.emacs.textprop
(:use [deuce.emacs-lisp :only (defun defvar)])
(:require [clojure.core :as c])
(:refer-clojure :exclude []))
(defun set-text-properties (start end properties &optional object)
"Completely replace properties of text from START to END.
The third argument PROPERTIES is the new property list.
If the optional fourth argument OBJECT is a buffer (or nil, which means
the current buffer), START and END are buffer positions (integers or
markers). If OBJECT is a string, START and END are 0-based indices into it.
If PROPERTIES is nil, the effect is to remove all properties from
the designated part of OBJECT."
)
typedclojure/typedclojure
(ns ^:no-doc typed.ann.clojure
"Type annotations for the base Clojure distribution."
#?(:cljs (:require-macros [typed.ann-macros.clojure :as macros]))
(:require [clojure.core :as cc]
[typed.clojure :as t]
#?(:clj [typed.ann-macros.clojure :as macros])
#?(:clj typed.ann.clojure.jvm) ;; jvm annotations
#?(:clj clojure.core.typed))
#?(:clj
(:import (clojure.lang PersistentHashSet PersistentList
APersistentMap #_IPersistentCollection
#_ITransientSet
IRef)
(java.util Comparator Collection))))
cc/replace (t/All [v] (t/IFn [(t/Map v v) :-> (t/Transducer v v)]
[(t/Map v v) (t/Vec v) :-> (t/Vec v)]
[(t/Map v v) (t/Seqable v) :-> (t/U (t/Vec v) (t/ASeq v))]))
;partial: wishful thinking (replaces the first 4 arities)
; (t/All [r b1 :.. b2 :..]
; [[b1 :.. b1 b2 :.. b2 :-> r] b1 :.. b1 :-> [b2 :.. b2 :-> r]])
clojure.string/blank? [(t/U nil t/Str) :-> t/Bool]
clojure.string/capitalize [t/Str :-> t/Str]
clojure.string/lower-case [t/Str :-> t/Str]
clojure.string/replace [(t/alt (t/cat t/Str t/Str t/Str)
(t/cat t/Str Character Character)
(t/cat t/Str t/Regex (t/U t/Str [t/Str :-> t/Str]))) :-> t/Str]
clojure.string/replace-first [(t/alt (t/cat t/Str t/Str t/Str)
(t/cat t/Str Character Character)
(t/cat t/Str t/Regex (t/U t/Str [t/Str :-> t/Str]))) :-> t/Str]
clojure.string/reverse [t/Str :-> t/Str]
clojure.string/trim [t/Str :-> t/Str]
clojure.string/trimr [t/Str :-> t/Str]
clojure.string/triml [t/Str :-> t/Str]
clojure.walk/keywordize-keys [t/Any :-> t/Any]
clojure.walk/macroexpand-all [t/Any :-> t/Any]
clojure.walk/postwalk [[t/Any :-> t/Any] t/Any :-> t/Any]
clojure.walk/postwalk-demo [t/Any :-> t/Any]
clojure.walk/postwalk-replace [(t/Map t/Any t/Any) t/Any :-> t/Any]
clojure.walk/prewalk [[t/Any :-> t/Any] t/Any :-> t/Any]
clojure.walk/prewalk-demo [t/Any :-> t/Any]
clojure.walk/prewalk-replace [(t/Map t/Any t/Any) t/Any :-> t/Any]
clojure.walk/stringify-keys [t/Any :-> t/Any]
clojure.walk/walk [[t/Any :-> t/Any] [t/Any :-> t/Any] t/Any :-> t/Any]
clojure.zip/zipper [[t/Any :-> t/Any] [t/AnySeqable :-> (t/U nil (t/Seq t/Any))]
[t/Any (t/U nil (t/Seq t/Any)) :-> t/Any]
t/Any
:-> (t/Vec t/Any)]
clojure.zip/seq-zip [t/Any :-> (t/Vec t/Any)]
clojure.zip/vector-zip [t/Any :-> (t/Vec t/Any)]
clojure.zip/xml-zip [t/Any :-> (t/Vec t/Any)]
clojure.zip/node [(t/Vec t/Any) :-> t/Any]
clojure.zip/branch? [(t/Vec t/Any) :-> t/Bool]
clojure.zip/children [(t/Vec t/Any) :-> (t/U nil (t/Seq t/Any))]
clojure.zip/root [(t/Vec t/Any) :-> t/Any]
clojure.zip/rightmost [(t/Vec t/Any) :-> (t/Vec t/Any)]
clojure.zip/right [(t/Vec t/Any) :-> t/Any]
clojure.zip/up [(t/Vec t/Any) :-> (t/U nil (t/Vec t/Any))]
clojure.zip/rights [(t/Vec t/Any) :-> t/Any]
clojure.zip/replace [(t/Vec t/Any) t/Any :-> (t/Vec t/Any)]
clojure.zip/down [(t/Vec t/Any) :-> (t/U (t/Vec t/Any) nil)]
clojure.zip/left [(t/Vec t/Any) :-> (t/U (t/Vec t/Any) nil)]
clojure.zip/lefts [(t/Vec t/Any) :-> (t/U (t/Vec t/Any) nil)]
clojure.zip/leftmost [(t/Vec t/Any) :-> (t/U (t/Vec t/Any) nil)]
clojure.zip/append-child [(t/Vec t/Any) t/Any :-> (t/Vec t/Any)]
clojure.zip/branch? [(t/Vec t/Any) :-> t/Bool]
clojure.zip/end? [(t/Vec t/Any) :-> t/Bool]
clojure.zip/insert-child [(t/Vec t/Any) t/Any :-> (t/Vec t/Any)]
clojure.zip/insert-left [(t/Vec t/Any) t/Any :-> (t/Vec t/Any)]
clojure.zip/insert-right [(t/Vec t/Any) t/Any :-> (t/Vec t/Any)]
clojure.zip/next [(t/Vec t/Any) :-> (t/Vec t/Any)]
clojure.zip/prev [(t/Vec t/Any) :-> (t/U (t/Vec t/Any) nil)]
;; more to say here
clojure.zip/path [(t/Vec t/Any) :-> t/Any]
clojure.zip/remove [(t/Vec t/Any) :-> (t/Vec t/Any)]