all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* sh-script beg-end of function
@ 2007-11-19 20:43 Andreas Röhler
  2007-11-21 12:05 ` Richard Stallman
  0 siblings, 1 reply; 13+ messages in thread
From: Andreas Röhler @ 2007-11-19 20:43 UTC (permalink / raw)
  To: emacs-devel

Hi all,

in sh-script-mode C-M-a jumped to the beginning of the
buffer, C-M-e to the end

with GNU Emacs 23.0.50.2 (i686-pc-linux-gnu, GTK+ Version 2.10.6) of 
2007-10-30 

To have a more convienent behaviour I made this:

;;;;;;;;;

(require 'newcomment)

(defcustom sh-beginning-of-function-regexp "^[A-Za-z_][A-Za-z_0-9]*" 
  ""
  :type 'regexp
  :group 'sh-script)

(defun sh-beginning-of-function ()
  "Re-search-backward sh-beginning-of-function-regexp nil t 1 "
  (interactive)
  (re-search-backward sh-beginning-of-function-regexp nil t 1))

(defcustom beginning-of-defun-function 'sh-beginning-of-function 
 ""
 :type 'symbol
 :group 'sh-script)

(defun sh-end-of-function (&optional arg)
  "Move forward to end of a function or command in sh-script.
With numeric argument, do it that many times.
"
  (interactive "p")
  (or arg (setq arg 1))
  (forward-line 1)
  ;; between functions, skip next beginning
  (when (eq 0 (car (parse-partial-sexp (point-min) (point))))
    (setq arg (1+ arg)))
  (let ((erf
	 (re-search-forward sh-beginning-of-function-regexp nil t arg)))
    (goto-char (match-beginning 0))
    (unless erf
      ;; already last top level form
      (goto-char (point-max)))
    (skip-chars-backward " \t\r\n\f")) 
  ;; skip comments 
  (while
      (progn
	(comment-normalize-vars) (comment-beginning))
    (forward-line -1)
    (end-of-line)
    (skip-chars-backward " \t\r\n\f")))

(defcustom end-of-defun-function 'sh-end-of-function 
 ""
 :type 'symbol
 :group 'sh-script)

(defun sh-set-beginning-of-function ()
  " "
  (interactive)
 (setq beginning-of-defun-function 'sh-beginning-of-function))

(defun sh-set-end-of-function ()
  " "
  (interactive)
  (setq end-of-defun-function 'sh-end-of-function))

(add-hook 'sh-mode-hook 'sh-set-beginning-of-function)
(add-hook 'sh-mode-hook 'sh-set-end-of-function)

;;;;;;;

Maybe I could use another form already existing?

Comments welcome

Andreas Röhler

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2007-11-24 13:45 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-19 20:43 sh-script beg-end of function Andreas Röhler
2007-11-21 12:05 ` Richard Stallman
2007-11-21 15:52   ` Andreas Röhler
2007-11-22  8:22     ` Richard Stallman
2007-11-21 20:19   ` Stefan Monnier
2007-11-22  7:26     ` Andreas Röhler
2007-11-22 17:39       ` Stefan Monnier
2007-11-22 18:56         ` Andreas Röhler
2007-11-22 21:49           ` Stefan Monnier
2007-11-23 15:33             ` Andreas Röhler
2007-11-23 16:34               ` Stefan Monnier
2007-11-24 13:45                 ` Andreas Röhler
2007-11-23 15:56             ` Andreas Röhler

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.