philjackson / philjackson.github.io Goto Github PK
View Code? Open in Web Editor NEWSomething a bit bloggy
License: MIT License
Something a bit bloggy
License: MIT License
Hi,
I like your function in https://github.com/philjackson/philjackson.github.io/blob/master/_posts/2021-07-26-export-an-environment-variable-to-emacs.md, but had a small issue with this:
$ export ASHTAS='abc " def""'
$ emacs-export ASHTAS
*ERROR*: End of file during parsing
and in emacs M-: (getenv "ASHTAS")
returns nil
.
It can also trigger execution of elisp code embedded in the environment variable and substitution of environment variables, at least, I was able to do this:
$ export ASHTAS='abc$PWD" (message "hello"));"'
$ emacs-export ASHTAS
$
then emacs displays "hello" in the echo area and in emacs M-: (getenv "ASHTAS")
returns "abc/home/philjackson"
(assuming your M-: default-directory
is "/home/philjackson"
)
I fixed the function as follows to translate "
to the octal escape sequence before sending the string
function export-emacs {
if [ "$(emacsclient -e t)" != 't' ]; then
return 1
fi
for name in "${@}"; do
value=$(eval echo \"\${${name}//\\\"/\\\\042}\")
emacsclient -e "(setenv \"${name}\" \"${value}\")" >/dev/null
done
}
Now M-: (let ((x (getenv "ASHTAS"))) (list x (length x)))
returns ("abc \" def\"\"" 11)
as expected.
Thank you for sharing your snippet! I would not have thought of writing it myself, but when I adopted it, I wanted to make it more robust. HTH!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.