Hot answers tagged

16

glucas is exactly correct, but to supplement his answer I have this piece of code I've used myself to make here doc insertion a little smarter. This advice, coupled with sh-electric-here-document-mode enabled, make it so that if you type two chevrons the automatic here doc will be created, but then if the next character you type is another chevron, it will ...


14

This is the correct behaviour. .bash_profile is for so-called login shells. Like when you log in to your computer in text mode, or in a terminal emulator to a different computer via ssh or telnet or ... .bashrc is meant for non-login shells, like when you are already logged in and start a new xterm, or in this case emacs' shell mode. Usually the ....


13

The code below use a font-lock rule with a function instead of a regexp, the function search for occurrences of $VAR but only when they are inside a double-quoted string. The function (syntax-ppss) is used to determine this. The font-lock rule use the prepend flag to add itself on top of the existing string highlighting. (Note that many packages use t for ...


13

This is caused by sh-electric-here-document-mode. When enabled, << will insert a here document skeleton. This is enabled by default. You can disable it with a hook, such as: (add-hook 'sh-mode-hook (lambda () (sh-electric-here-document-mode -1)))


13

In addition to the points made by @pingi, you can also use a separate configuration file that will be loaded only for the emacs shell (M-x shell): From the manual page (emacs) Interactive Shell: Emacs sends the new shell the contents of the file ‘~/.emacs_SHELLNAME’ as input, if it exists, where SHELLNAME is the name of the file that the shell was ...


12

The -i flag requests that Bash run in interactive mode, which requires a terminal. The solution is to leave the shell-command-switch variable at its default value, which is just -c. If you really need to run Bash in interactive mode, you will need to run it in a pseudo-terminal, by using start-file-process with process-connection-type bound to t.


12

According to https://lists.gnu.org/archive/html/emacs-orgmode/2015-11/msg00425.html ob-sh was renamed ob-shell in org 8.2 ... and I cite from there: org-babel-get-header was removed in 0d000f5 (babel: small change in API., 2015-10-29), but the old ob-sh.el is still trying to call it. That means you should replace (sh . t) by (shell . t) in your call of ...


11

The ^[] noise is coming from various terminal control characters in your shell prompt. Try echo $PS1 to see the full sequence, and try e.g. export PS1='$ ' to see that a simpler prompt string removes that particular problem. For the encoding, you might try making utf-8 your preferred encoding: (prefer-coding-system 'utf-8) Setting up the prompt Emacs ...


10

I had this exact same problem but it had nothing to do with RVM on ( which I also have ) on my Ubuntu-16.10 machine. It was related to by custom prompt (PS1) The issue was the prompt PS1. This fix : https://stackoverflow.com/questions/6954479/emacs-tramp-doesnt-work Essentially in your .bashrc case "$TERM" in "dumb") export PS1="...


10

You're nearly there; you have a :prologue set, via exec 2>&1, to capture both stdout and stderr. To finish this, you just need two things: :results: output to inform Babel that you want the results from what gets written out, not by what the code returns; and :epilogue "true", to do what you're doing above with || true unilaterally and always without ...


9

Setting sh-basic-offset to the required indentation is what is needed - but what I didn't realise is, it's also necessary to close and reopen all shell script files before the customisation takes effect. I can't remember ever having to do this before in emacs.


9

You can't copy-paste between Emacs and a shell without using a system-wide copy-paste facility. Text terminals in general do not provide a copy-paste facility. It seems that you're running this terminal Emacs in a terminal window in a window environment. Window environments do provide copy-paste; that's what happens when you use the mouse. However, this ...


9

Thanks J David for forcing me to look more deeply. flycheck.el defines sh-bash, the checker used for bash; and that has a next-checker known as sh-shellcheck. Ans, as Jordon is points out, that invokes shellcheck Poking around in 2 reveals how to supress warning in a selective manner: function f(){ # shellcheck disable=SC2029 ssh foo "$@" } ...


8

Best solution: Install exec-path-from-shell. From the documentation, after calling (package-initialize), add the following to your .emacs file: (when (memq window-system '(mac ns x)) (exec-path-from-shell-initialize)) Another solution: Add the following to your .emacs file: (setq exec-path (append exec-path '("~/.nvm/versions/node/v6.3.0/bin"))) Your ...


8

No, you don’t want to use -i because you’re not launching an interactive shell. That is, this shell will not be connected to a terminal that the user can type in. It is instead going to be connected to a pipe so that Emacs can read whatever it prints. Removing the -i option will prevent Bash from trying to use inappropriate ioctls on the stdout and stdin, ...


6

Although it is not clearly documented in its man page, emacsclient doesn't seem to accept a full command (i.e. program + arguments) as the alternate editor, only a program. You could write a small shell script: #!/bin/bash exec emacs -q -nw "$@" and use it as the alternate editor: export EDITOR='emacsclient -a PATH_TO_YOUR_SCRIPT'


6

Because bash it is not the GUI program. Start your terminal emulator instead like (start-process "xterm" nil (executable-find "xterm"))


5

apt installs an old version of flycheck, https://github.com/koalaman/shellcheck/issues/704 that does not support --external-sources, this particular commit has been merged at flycheck recently https://github.com/flycheck/flycheck/pull/1256/files/7b35a1b17e415ecc8f9fc04b3a043a3afb40599c and make use of such feature. The solution is simple, just opt-out of it. ...


5

You can find out how your code is executed by checking ob-shell.el. As for your particular example, your code is passed to bash as stdin, something like the following $ echo 'echo $VAR_DEFINED_IN_BASHRC' | bash It will not work, you need the following instead $ echo 'echo $VAR_DEFINED_IN_BASHRC' | bash -i So you need to run bash interactively (-i) to ...


5

Perhaps something along the following lines: emacs -Q --eval='(progn (find-file "/path/to/file") (goto-char (org-find-exact-headline-in-buffer "org-headline")))'


4

It looks like you've run the exec-path-from-shell from a Tramp buffer, so when it runs the shell, it attempts to do its magic on the remote server and then set the environment variables in your local emacs instance. That's almost certainly not what you want, and it's not a case that exec-path-from-shell is designed for. It looks like it's Tramp or your Tramp ...


4

I improved @Lindydancer's answer in the following ways: Inlined the sh-script-extra-font-lock-is-in-double-quoted-string function, as it was only used once Escaping the variable works. Numeric variables ($10, $1, etc) are highlighted. Break for code (defun sh-script-extra-font-lock-match-var-in-double-quoted-string (limit) "Search for variables in ...


4

The only way you would get that error is if you were using the shellcheck checker, in order to remove these warnings you need to customize the command flycheck is using for shellcheck, there is no built in way to customize the existing shellcheck checker, but you can create a new checker with that feature. You'll need to create a new flycheck checker that ...


4

For the indentation after the | you should be able to get the right result by going to the incorrect line (i.e. the one that starts with grep) and then do M-x smie-config-set-indent RET before "|" RET nil RET. But smie-config is not up to the task when it comes to tweaking the behavior of the close paren in the way you want. For that you'll need actual ...


4

I set-basic-offset to 2 but that didn't seem to work, I went back pressed C-h v sh-<TAB> and realized that there was a sh-indentation I set that variable to 2 and everything seems to work like a charm now.


3

In conjunction with the assistance of the original poster in the comments above, here is the final solution: (defun org-icalendar-open-ics-file (file) (start-process "org-icalendar-open-ics-file-process" nil "open" "-a" "/Applications/Calendar.app" file)) (add-hook 'org-icalendar-after-save-hook 'org-icalendar-open-ics-file)


3

emacsclient has a -a option which lets you specify an alternate editor to use if there is not an emacs process with a running server. So emacsclient -a emacs may do what you want. The alternate editor can also be specified to emacsclient via the ALTERNATE_EDITOR environment variable. As for which of EDITOR or VISUAL to set: EDITOR was traditionally used ...


3

FILES should be a list of file names to convert So presumably you actually need (htmlize-many-files (list \"{}\")) in that shell script.


3

Try this: emacsclient -e '(buffer-list)'


Only top voted, non community-wiki answers of a minimum length are eligible