emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sh-here-document-word should be customizable


From: Kevin Rodgers
Subject: Re: sh-here-document-word should be customizable
Date: Fri, 08 Apr 2005 10:13:59 -0600
User-agent: Mozilla Thunderbird 0.9 (X11/20041105)

Thanks,> I don't know about most users, but I find it annoying that:
>
> 1. The "EOF\n\nEOF" string is inserted and point is moved between the
>    newlines, as soon as I type "<<".  I almost always use the "<<-"
>    syntax, so that I can indent the here document between the command
>    and terminating word by tabs for readability.  Could
>    sh-maybe-here-document be enhanced to wait (say 1 second) for a `-'
>    input event before inserting the template, and then insert a tab
>    before point if it sees the `-'?
>
> 2. I prefer a space after redirection operators, but putting a space at
>    the beginning of sh-here-document-word doesn't produce a valid shell
>    command, because the same space is inserted by
>    sh-maybe-here-document.  (The shell only ignores leading tabs -- not
>    spaces -- before the word, and only if the "<<-" syntax is used.)

Here's a patch that implements (1) as described and addresses (2) by
inserting a space after the redirection operator if there is a space
before it.  It's simpler to combine them in this single patch, but it's
easy to identify which bits of code are for each feature if you don't
want both: (1) uses next-command-event and (2) uses redirection-point.

The patch also makes ARG optional and binds it via the p interactive
code, according to convention.

*** emacs-21.3/lisp/progmodes/sh-script.el~     Tue Oct 22 02:14:34 2002
--- emacs-21.3/lisp/progmodes/sh-script.el      Thu Apr  7 18:03:56 2005
***************
*** 3449,3465 ****



! (defun sh-maybe-here-document (arg)
"Insert self. Without prefix, following unquoted `<' inserts here document.
  The document is bounded by `sh-here-document-word'."
!   (interactive "*P")
!   (self-insert-command (prefix-numeric-value arg))
!   (or arg
        (not (eq (char-after (- (point) 2)) last-command-char))
        (save-excursion
        (backward-char 2)
        (sh-quoted-p))
!       (progn
        (insert sh-here-document-word)
        (or (eolp) (looking-at "[ \t]") (insert ? ))
        (end-of-line 1)
--- 3449,3472 ----



! (defun sh-maybe-here-document (&optional arg)
"Insert self. Without prefix, following unquoted `<' inserts here document. + Unquoted `-' quickly following `<<' indents here document with tab character.
  The document is bounded by `sh-here-document-word'."
!   (interactive "*p")
!   (self-insert-command arg)
!   (or current-prefix-arg
        (not (eq (char-after (- (point) 2)) last-command-char))
        (save-excursion
        (backward-char 2)
        (sh-quoted-p))
!       (let ((next-command-event (if (not (sit-for 1 nil t))
!                                     (read-event)))
!             (redirection-point (- (point) 2)))
!         (when (equal next-command-event ?-)
!           (insert ?-))
!         (when (equal (char-before redirection-point) ? )
!           (insert ? ))
        (insert sh-here-document-word)
        (or (eolp) (looking-at "[ \t]") (insert ? ))
        (end-of-line 1)
***************
*** 3467,3472 ****
--- 3474,3484 ----
            (sh-quoted-p)
          (end-of-line 2))
        (newline)
+         (cond ((equal next-command-event ?-)
+                (insert ?\t))
+               (next-command-event
+                (setq unread-command-events
+                      (cons next-command-event unread-command-events))))
        (save-excursion (insert ?\n sh-here-document-word)))))

  
--
Kevin Rodgers





reply via email to

[Prev in Thread] Current Thread [Next in Thread]