From 9df4ec5e9044e92e792ba9e8cb714603e32c5cc5 Mon Sep 17 00:00:00 2001 From: Leo Liu Date: Thu, 16 May 2013 11:41:52 +0800 Subject: [PATCH] * simple.el (prog-indent-sexp): Indent enclosing defun. --- lisp/ChangeLog | 4 ++++ lisp/simple.el | 18 ++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index c579642642e..0b233385eb7 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,7 @@ +2013-05-16 Leo Liu + + * simple.el (prog-indent-sexp): Indent enclosing defun. + 2013-05-15 Glenn Morris * cus-start.el (show-trailing-whitespace): Move to editing basics. diff --git a/lisp/simple.el b/lisp/simple.el index e4bde7c358c..f81b02b0acf 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -380,12 +380,18 @@ Other major modes are defined by comparison with this one." map) "Keymap used for programming modes.") -(defun prog-indent-sexp () - "Indent the expression after point." - (interactive) - (let ((start (point)) - (end (save-excursion (forward-sexp 1) (point)))) - (indent-region start end nil))) +(defun prog-indent-sexp (&optional defun) + "Indent the expression after point. +When interactively called with prefix, indent the enclosing defun +instead." + (interactive "P") + (save-excursion + (when defun + (end-of-line) + (beginning-of-defun)) + (let ((start (point)) + (end (progn (forward-sexp 1) (point)))) + (indent-region start end nil)))) (define-derived-mode prog-mode fundamental-mode "Prog" "Major mode for editing programming language source code." -- 2.39.2