Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

When editing a bash script file with emacs, and trying to enter <<<, at the second < emacs insert a template for a here document, like in the following example:

<<EOF

EOF

This is not the desired output, because I would enter a literal <<<.

For the moment I resort to entering < < <, and then deleting spaces, but I prefer to being allowed to enter it directly.

share|improve this question
2  
Not that I care too much, but It would be nice to leave a comment for a downvote. –  enzotib Sep 5 '11 at 15:08
add comment

6 Answers

up vote 7 down vote accepted

Bind < to self-insert-command in bash mode and then it will insert only the character.

By default it is bound to sh-maybe-here-document when in bash mode and that function does the auto-insertion.

Here is a way to rebound the key:

(add-hook 'sh-set-shell-hook 'my-disable-here-document)

(defun my-disable-here-document ()
  (local-set-key "<" 'self-insert-command))
share|improve this answer
    
Can you please give some more information on what to exactly insert in the init file? Sorry, but I am a beginner emacs's user. –  enzotib Sep 5 '11 at 10:04
    
I added a simple example to my answer. It disables the automatic insertion in every kind of shell, not just bash, but probaly that's what you want anyway. –  Tom Sep 5 '11 at 10:31
add comment

There is actually no need for Tom 's custom my-disable-here-document function rebinding the keys. This feature can be enabled and disabled with sh-electric-here-document-mode:

(add-hook 'sh-mode-hook
          (lambda ()
            (sh-electric-here-document-mode -1)))

(It can also be toggled for the active buffer via M-x sh-electric-here-document-mode.)

share|improve this answer
add comment

If the only reason you want to disable the here-doc behaviour is that it prevents you from inserting a here-string <<<, then binding C-< to a function which contains (insert "<<<") will work, and still allow the auto here-doc template

(defun my-here-string() 
  "Insert <<< (eg. for a bash here-string)" 
  (interactive)
  (insert "<<<"))
(global-set-key (kbd  "C-<") 'my-here-string)
share|improve this answer
1  
Thank you, interesting solution, but I still prefer @Tom's answer, because I consider that completion wrong for a bash script file. –  enzotib Sep 5 '11 at 16:37
add comment

Type < C-q < <

share|improve this answer
    
It is shorter than my workaround, and perhaps useful for other situations too, but not exactly what I was looking for. Thank you anyway. –  enzotib Sep 5 '11 at 11:48
add comment

After taking a look at: http://web.mit.edu/dosathena/sandbox/emacs-19.28/lisp/sh-script.el I came up with this solution:

;; disable the automatic EOF generation in Shell Mode
(defvar sh-use-prefix nil
  "If non-nil when loading, `$' and `<' will be  C-c $  and  C-c < .")
(defvar sh-mode-map
  (let ((map (make-sparse-keymap)))
    (define-key map (if sh-use-prefix "\C-c<" "<")
      (local-set-key "<" 'self-insert-command))
   map)
  "Keymap used in Shell-Script mode.")
share|improve this answer
add comment

I enter <<< as M-3< in the shell mode.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.