separate
provide function that help you to separate setting
by system environment, such as system-name given by (system-name)
,
Emacs version, OS, and so on.
separate-system-predicate-alist
(optional),
and use separate-setq
or separate-cond
.
See also System-Predicate Section and Keywords Section.
;; Define some system-predicate. This is optional.
;; If you define this, you can use symbol as system-predicate(like condicate).
(setq separate-system-predicate-alist
'(;; (symbol . system-predicate)
(pc-name1 . "MY-PC-NAME1")
(pc-name2 . "MY-PC-NAME2")
(my-candicate . (:eval (abc)))
))
(separate-setq foo
(;; (system-predicate . value)
(pc-name1 . 1)
(pc-name2 . 2)
("MY-PC-NAME3" . 3)
(windows-nt . 4)
((:eval (something) (bar)) . 5)
((:package-available 'baz) . 6)
((:and windows-nt (:eval (def))) . 7)
((:system-predicates "MY-PC-NAME4" gnu/linux) . 8)
(default . 0)))
Value of foo
is set to:
- If your
system-name
is “MY-PC-NAME1”: 1 - Else if your system-name is “MY-PC-NAME2”: 2
- Else if your system-name is “MY-PC-NAME3”: 3
- Else if your
system-type
iswinodows-nt
: 4 - Else if returned value by
(something) (bar)
isnon-nil
: 5 - Else if
(featurep 'baz)
isnon-nil
: 6 - Else if your
system-type
iswindows-nt
AND returned value by(def)
isnon-nil
: 7 - Else if your system-name is “MY-PC-NAME4” OR your
system-type
isgnu/linux
: 8 - If all of
system-predicates
are invalid: 0
system-predicate
means object which can separate system environment.system-predicate
can be list, symbol, number or string.
- There are 2 types of listed-system-predicate.
- One type is:
- Have keyword in the
car
. All keywords start “:”. cdr
of the list is argument. See Keywords Section.
- Have keyword in the
- The other type is:
- Don’t have keyword in the
car
. This is put:system-predicates
keyword automatically. See system-predicates Section.
- Don’t have keyword in the
- This is interpreted as
system-predicate
defined inseparate-system-predicate-alist
,
or system-type (same as :os
keyword). See separate-system-predicate-alist Section.
- the symbol
default
is special symbol. Element including this is evaluated only when all of otherseprators
are invalid.
;;Define symbol system-predicate.
(setq separate-system-predicate-alist
'(
;; This system-predicate means "if `system-name' is "my-windows",".
;; See also String Section and :system-name Section.
(my-win . "my-windows")
;; This system-predicate means "if `system-type' is `gnu/linux' and
;; if `system-name' is "MY-PC,". See also String Section and
;; :and Section.
(my-linux . (:and gnu/linux "MY-PC"))
;; You can make alias of symbol sparator.
(my-l . my-linux)
))
(separate-setq foo
(
;; If `system-name' is "my-windows", `foo' is set to 1.
(my-win . 1)
;; If `system-type' is `gnu/linux' and if `system-name' is "MY-PC,
;; `foo' is set to 2.
(my-linux . 2)
;; Otherwise, `foo' is set to 3.
(default . 3)
))
;; below is absolutely same as above.
(separate-setq foo
(
(my-win . 1)
(default . 3) ; You can write default anywhere.
(my-linux . 2)
))
This is interpreted as has :emacs-version>=
keyword.
See emacs-version Section.
This is interpreted as has :system-name
keyword.
See system-name Section.
- This keyword accept multiple argument of
string
. if at least one of argument is same as system-name, thissystem-predicate
is valid. - Keyword
:system-name
is optional.
(separate-setq foo
(;; (system-predicate . value)
;; if system-name is "MY-PC-1", `foo' is
;; set to 1
((:system-name "MY-PC-1") . 1)
;; :system-name is optional.
;; So This is same as ((:system-name "MY-PC-2") . 2)
("MY-PC-2" . 2)
;; you can put multiple argument.
;; If system-name is either "MY-PC-3" or "MY-PC-4",
;; `foo' is set to 3
((:system-name "MY-PC-3" "MY-PC-4") . 3)
;; :system-name is optional even when multiple argument.
(("MY-PC-6" "MY-PC-7" "MY-PC-8") . 4)
))
- This keyword accept 1 or 2 argument(s) of number. First argument is
M
, and second argument (optional) ism
. If emacs version is same or higher thanM.m
, thissystem-predicate
is valid. - If you use only first argument, you can write number of major-version as system-predicate.
(separate-setq foo
(
;; If emacs version is 25.3 or higher, `foo' is set to 1
((:emacs-version>= 25 3) . 1)
;; If emacs version is 25(.0) or higher, `foo' is set to 2
((:emacs-version>= 25) . 2)
;; Same as previous one.
(25 . 2)
))
- This keyword accept multiple arguments of S expression. If returned value
of those S expression is
non-nil
, thissystem-predicate
is valid.
(separate-setq foo
(
;; If system-name include the string "WIN",
;; `foo' is set to 1
((:eval (string-match "WIN" (system-name))) . 1)
;; multiple S expressions is permitted.
;; If `(progn (bar) (baz))' return t, `foo' is set to 5
((:eval (bar) (baz)) . 5)
;; This is similar to `(default . 2)', but in this case,
;; cons-cells below this one will NOT seen, while all cons-cells
;; are seen in case of "default".
((:eval t) . 2)
;; This cons-cell is not seen. In the other words, `foo' is never set
;; to 3.
("SOME-PC" . 3)
))
- This keyword accept multiple arguments of symbol. If one of arguments is
same as
system-type
, thissystem-predicate
is valid. See also emacs help ofsystem-type
, and system-predicates Section. - Keyword
:os
is optional.
(separate-setq foo
(
;; If OS is Windows, `foo' is set to 1.
((:os windos-nt) . 1)
;; multiple arguments is permitted.
;; If OS is either GNU/Linux or Cygwin (even not OS),
;; `foo' is set to 2.
((:os gnu/linux cygwin) . 2)
;; their symbols of `system-type' can be used as symbol system-predicate defined in
;; `separate-system-predicate-alist'. So you can write this instead of above.
;; See also :system-predicates Seciton.
((gnu/linux cygwin) . 2)
))
- This keyword accept multiple argument of feature (symbol). If all arguments
are returned
non-nil
when passed tofeaturep
, thissystem-predicate
is valid.
(separate-setq foo
(
;; If cl-lib is provided (meaning `(featurep 'cl-lib)' return t),
;; `foo' is set to 1
((:package-available cl-lib) . 1)
;; Multiple arguments are permitted.
;; Only if `helm', `company', and `ido' is all provided,
;; `foo' is set to 2.
((:package-available helm company ido) . 2)
))
- These keywords accept multiple arguments of
system-predicate
. If at least one ofsystem-predicates
of arguments is valid, thissystem-predicate
is valid. - those keywords are optional.
(separate-setq foo
(;; (system-predicate . value)
;; if system-name is "MY-PC-1" or "MY-PC-2", or if system-type
;; is `windows-nt', `foo' is set to 1.
((:system-predicates ; This can be `:or' or `:alias'
(:system-name "MY-PC-1")
"MY-PC-2"
windows-nt)
. 1)
;; You can use this keyword with all system-predicate.
;; If cl-lib and ido is all provided, or if `bar' is a function,
;; `foo' is set to 2.
((:or
(:package-available cl-lib ido)
(:eval (functionp 'bar)))
. 2)
))
- These keywords accept multiple arguments of
system-predicate
. If allsystem-predicates
of arguments are valid, thissystem-predicate
is valid.
(separate-setq foo
(;; (system-predicate . value)
;; if system-name is "MY-PC-1", AND if system-type is `windows-nt',
;; `foo' is set to 1.
((:and
(:system-name "MY-PC-1")
windows-nt)
. 1)
;; You can use this keyword with all system-predicate.
;; If cl-lib and ido is all provided, AND if `bar' is a function,
;; `foo' is set to 2.
((:or
(:package-available cl-lib ido)
(:eval (functionp 'bar)))
. 2)
))
- An associated list. Each element is cons cell,
(symbol . system-predicate)
. In this package, you can use thesymbol
as thesystem-predicate
. - See also How to Use Section as example.
- In the future, we will provide some functions to define
symbol-system-predicate
like this.
- Set value of
VARIABLE
depend onSYSTEM-PREDICATE
below. - Each element of
ALIST
is(SYSTEM-PREDICATE . VALUE)
, andVARIABLE
is set toVALUE
ifSYSTEM-PREDICATE
is valid. - If there are some cons cells whose car (=
SYSTEM-PREDICATE
) is valid, upstream element is used, and rest of them is not evaluated. - in the cons cell whose
SYSTEM-PREDICATE
isdefault
, itsVALUE
is used only when any otherSYSTEM-PREDICATE
isn’t valid. (separate-set 'a ((b . c) ...))
is absolutely same as(separate-setq a ((b . c) ...))
.
- Same as
separate-set
, butVARIABLE
doesn’t have to be quoted. - See How to Use Section as example.
- Same as
separate-set-no-eval
, butVALUE
are NOT evalueted.
- Same as
separate-setq-no-eval
, butVALUE
are NOT evalueted.
- Similar to
cond
, but useSYSTEM-PREDICATE
instead ofCANDICATE
. IfSYSTEM-PREDICATE
is valid, evaluateBODY
. - Priority of each clause is same as
separate-set
.
;; Define some system-predicate. This is optional.
;; If you define this, you can use symbol as system-predicate(like condicate).
(setq separate-system-predicate-alist
'(;; (symbol . system-predicate)
(pc-name1 . "MY-PC-NAME1")
(pc-name2 . "MY-PC-NAME2")
(my-candicate . (:eval (abc)))
))
(separate-cond
;; (system-predicate . value)
(pc-name1 1)
(pc-name2 2)
("MY-PC-NAME3" 3)
(windows-nt 4)
((:eval (something) (bar)) 5)
((:package-available 'baz) 6)
((:and windows-nt (:eval (def))) 7)
((:system-predicates "MY-PC-NAME4" gnu/linux) 8)
(default 0))
The latter S expression returns:
- If your
system-name
is “MY-PC-NAME1”: 1 - Else if your system-name is “MY-PC-NAME2”: 2
- Else if your system-name is “MY-PC-NAME3”: 3
- Else if your
system-type
iswinodows-nt
: 4 - Else if returned value by
(something) (bar)
isnon-nil
: 5 - Else if
(featurep 'baz)
isnon-nil
: 6 - Else if your
system-type
iswindows-nt
AND returned value by(def)
isnon-nil
: 7 - Else if your system-name is “MY-PC-NAME4” OR your
system-type
isgnu/linux
: 8 - If all of
system-predicates
are invalid: 0
This package is licensed by GPLv3. See LICENSE.