-1
(defun buffer-to-shell()
  (let (buffer mark-whole-buffer)))
  (shell-command-on-region start end "sed s/foo/bar/") ;; start, end not defined
  )

As you might see there are undefined variables start and end in the function call for shell-command-on-region.

I would like the function buffer-to-shell to just mark the whole active buffer and pass it's region fields to the shell command function. I do not know how to get those to fields out of the result of mark-whole-buffer which I am assigning to the local variable buffer (which also may be redundant.

Solution

(defun buffer-to-shell()
  "push the whole buffer to shell command sed"
  (interactive)
  (shell-command-on-region (point-min) (point-max) "sed s/foo/bar/")
  )

yields Wrong type argument: commandp, buffer-to-shell

Drew
  • 75,699
  • 9
  • 109
  • 225
xetra11
  • 167
  • 7
  • 1
    Possible duplicate of [Bind \`C-x 8 l\` to typing lambda (λ)](https://emacs.stackexchange.com/questions/14118/bind-c-x-8-l-to-typing-lambda-%ce%bb) – Drew Oct 07 '18 at 01:24
  • Your function `buffer-to-shell` does not satisfy the predicate `commandp` - it is not a command. You need to add an `interactive` spec to make it a command. – Drew Oct 07 '18 at 01:25
  • Possible duplicate of [Why can't I bind my function to a key or call it with M-x?](https://emacs.stackexchange.com/questions/45401/why-cant-i-bind-my-function-to-a-key-or-call-it-with-m-x) – erikstokes Oct 17 '18 at 14:58

1 Answers1

1

You don't need a region when you're calling this function from code. You only need positions in buffer, and you can get these with (point-min) and (point-max).