emacs/var/elfeed/db/data/3b/3bae125fd8707c77e7711a5e5b023582d3e49f76
2022-01-03 12:49:32 -06:00

19 lines
1.6 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>How does the process of script creation typically go? You create a file (e.g. <code class="language-plaintext highlighter-rouge">script.py</code>),
you write some code in it, and finally you make the file executable, so you can
run it directly (e.g. by typing <code class="language-plaintext highlighter-rouge">./script.py</code>). Turns out that Emacs has one very
specific helper for making a script executable, namely the function
<code class="language-plaintext highlighter-rouge">executable-make-buffer-file-executable-if-script-p</code>.</p>
<p>What the function does is to check if the buffer file has a shebang (e.g. <code class="language-plaintext highlighter-rouge">#!/bin/ruby</code>) in it and then it modifies its permissions, if necessary. The function is meant to be used
in a hook, most typically <code class="language-plaintext highlighter-rouge">after-save-hook</code>:</p>
<div class="language-emacs-lisp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">(</span><span class="nv">add-hook</span> <span class="ss">'after-save-hook</span>
<span class="ss">'executable-make-buffer-file-executable-if-script-p</span><span class="p">)</span>
</code></pre></div></div>
<p>Ive been using this little trick for ages, and I was reminded of it today
when I came across <a href="https://github.com/bbatsov/prelude/issues/1343">this Prelude issue</a>. I guess in some cases making a file executable automatically might be
undesirable, but Ive never ran into any issues myself.</p>
<p>Thats all I have for you today. Feel free to share other tips for working with
scripts in Emacs in the comments. Keep hacking!</p>