<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>lisp on Nistara</title>
    <link>/tags/lisp/</link>
    <description>Recent content in lisp on Nistara</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    <copyright>Nistara Randhawa</copyright>
    <lastBuildDate>Wed, 21 Feb 2018 00:00:00 +0000</lastBuildDate>
    
	<atom:link href="/tags/lisp/index.xml" rel="self" type="application/rss+xml" />
    
    
    <item>
      <title>Emacs: send line or region to shell</title>
      <link>/post/emacs-send-line-or-region-to-shell/</link>
      <pubDate>Wed, 21 Feb 2018 00:00:00 +0000</pubDate>
      
      <guid>/post/emacs-send-line-or-region-to-shell/</guid>
      <description>While exploring GRASS GIS and writing scripts to run its commands, I realized it would be way more convenient to have a shortcut for sending lines to the shell for evaluation. This, instead of copy-pasting each sentence from the script to the shell buffer (ugh).
Thanks to this answer on Stackoverflow, I was able to do just that with a minor tweak.
(defun sh-send-line-or-region (&amp;amp;optional step) (interactive ()) (let ((proc (get-process &amp;quot;shell&amp;quot;)) pbuf min max command) (unless proc (let ((currbuff (current-buffer))) (shell) (switch-to-buffer currbuff) (setq proc (get-process &amp;quot;shell&amp;quot;)) )) (setq pbuff (process-buffer proc)) (if (use-region-p) (setq min (region-beginning) max (region-end)) (setq min (point-at-bol) max (point-at-eol))) (setq command (concat (buffer-substring min max) &amp;quot;\n&amp;quot;)) (with-current-buffer pbuff (goto-char (process-mark proc)) (insert command) (move-marker (process-mark proc) (point)) (setq comint-scroll-to-bottom-on-output t) ) (process-send-string proc command) (display-buffer (process-buffer proc) t) (when step (goto-char max) (next-line)) )) (defun sh-send-line-or-region-and-step () (interactive) (sh-send-line-or-region t))  And because I&amp;rsquo;ve set &amp;lt;s-return&amp;gt; to ess-eval-region-or-line-and-step, I set the same shortcut for sending commands to the shell for evaluation.</description>
    </item>
    
  </channel>
</rss>