emacs-devel
[Top][All Lists]
Advanced

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

sh-script beg-end of command


From: Andreas Röhler
Subject: sh-script beg-end of command
Date: Thu, 22 Nov 2007 09:10:49 +0100
User-agent: KMail/1.9.5

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 <address@hidden>
;; 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 via email to

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