unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Kevin Rodgers <ihs_4664@yahoo.com>
Subject: Re: sh-here-document-word should be customizable
Date: Fri, 08 Apr 2005 10:13:59 -0600	[thread overview]
Message-ID: <d36afp$d6q$1@sea.gmane.org> (raw)
In-Reply-To: <d348n1$h1j$1@sea.gmane.org>

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)))))

   \f
-- 
Kevin Rodgers

  reply	other threads:[~2005-04-08 16:13 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-07 17:09 sh-here-document-word should be customizable Ted Zlatanov
2005-04-07 21:31 ` Kevin Rodgers
2005-04-08 16:13   ` Kevin Rodgers [this message]
2005-04-08 17:02     ` Glenn Morris
2005-05-02 16:33   ` Daniel Brockman
2005-04-08  3:22 ` Richard Stallman
2005-04-11 17:30   ` Ted Zlatanov
2005-04-13 18:56     ` Glenn Morris

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='d36afp$d6q$1@sea.gmane.org' \
    --to=ihs_4664@yahoo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).