all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Andreas Röhler" <andreas.roehler@online.de>
To: emacs-devel@gnu.org
Subject: sh-script beg-end of command
Date: Thu, 22 Nov 2007 09:10:49 +0100	[thread overview]
Message-ID: <200711220910.50079.andreas.roehler@online.de> (raw)


Hi all,

let's consider behaviour of `sh-end-of-command' with
this peace of code from install.sh

M-e stops at

while [ x"$1" != x ]; do
________________________|___
    case $1 in
______________|___________    
	-c) instcmd="$cpprog"
__________|__________________	
	    shift
_________________|___________	    
	    continue;;
____________________|_________	    


First both stops seem ok, third not, fifth at least
questionable.

Try M-e and M-a from the very beginning of the script
to and fro: IMO stops are nearly not predictable.

Changed behaviour to that 

M-a stops at beginnings
and M-e at ends 
of separated lines of code, 

skipping comments and empty lines and single closing braces.

Below der code, any comments welcome.

Thanks


Andreas Röhler

;;; sh-beg-end-of-command.el --- Something useful for
;;; M-a and M-e in sh-script

;; Copyright (C) 2007  Andreas Röhler

;; Author: Andreas Röhler <andreas.roehler@online.de>
;; Keywords: languages

;; This file is free software; you can redistribute it
;; and/or modify it under the terms of the GNU General
;; Public License as published by the Free Software
;; Foundation; either version 3, or (at your option)
;; any later version.

;; This file is distributed in the hope that it will be
;; useful, but WITHOUT ANY WARRANTY; without even the
;; implied warranty of MERCHANTABILITY or FITNESS FOR A
;; PARTICULAR PURPOSE.  See the GNU General Public
;; License for more details.

;; You should have received a copy of the GNU General
;; Public License along with GNU Emacs; see the file
;; COPYING.  If not, write to the Free Software
;; Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.

;;; Commentary:

;; Jumps to the beginning or end of command in a given
;; line, forward or backward next beginning or end with
;; repeated execution. With argument doing this as many
;; times.

;;; Code:



(require 'newcomment.el)

(defun sh-beginning-of-command (&optional arg) 
  "Move point to successive beginnings of commands."
  (interactive "p")
  (let ((arg (or arg 1)))
    (while (< 0 arg)
      (forward-line (- arg))
      (setq arg (1- arg))
      ;; skip comments and empty lines and closing braces
      (while (or (empty-line-p)
		 (looking-at (concat "^[ \t]*" comment-start))
		 (looking-at "}"))
	(forward-line -1))
      (back-to-indentation)
      ;; an indented comment may be followed by empty lines
      (while (or (empty-line-p)
		 (looking-at (concat "^[ \t]*" comment-start))
		 (looking-at "}"))
	(forward-line -1))
      (back-to-indentation))))

(defun sh-end-of-command (&optional arg) 
  "Move point to successive ends of commands."
  (interactive "p")
  (let ((arg (or arg 1))
	(pos (point)))
    (end-of-line)
    (skip-chars-backward " \t\r\n\f" (line-beginning-position))
    (unless (eq pos (point))
      ;; point has moved
      (setq arg (1- arg)))
    (while (< 0 arg)
      (forward-line arg)
      (setq arg (1- arg)))
    (end-of-line)
    (skip-chars-backward " \t\r\n\f" (line-beginning-position))
    (while (or
	    (empty-line-p)
	    (save-excursion
	      (and
	       (re-search-backward (concat "^[ \t]*" comment-start) 
(line-beginning-position) t 1)
	       (not (looking-back "[[:alnum:]]\\{2,\\}.*" 
(line-beginning-position)))))) 
      (forward-line 1)
      (end-of-line))
    (skip-chars-backward " \t\r\n\f")
    (when (and
	   (re-search-backward (concat "^[ \t]*" comment-start) 
(line-beginning-position) t 1)
	   (looking-back "[[:alnum:]]\\{2,\\}.*" (line-beginning-position)))
      (skip-chars-backward " \t\r\n\f"))))


(provide 'sh-beg-end-of-command)
;;; sh-beg-end-of-command.el ends here

             reply	other threads:[~2007-11-22  8:10 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-22  8:10 Andreas Röhler [this message]
2007-11-22 12:13 ` sh-script beg-end of command Andreas Röhler
2007-11-22 16:23 ` Richard Stallman
2007-11-24 15:23   ` Andreas Röhler

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

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

  git send-email \
    --in-reply-to=200711220910.50079.andreas.roehler@online.de \
    --to=andreas.roehler@online.de \
    --cc=emacs-devel@gnu.org \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.