/[emacs]/emacs/lisp/emacs-lisp/lisp.el
ViewVC logotype

Diff of /emacs/lisp/emacs-lisp/lisp.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.48.4.1 by handa, Fri Apr 16 12:50:13 2004 UTC revision 1.48.4.2 by miles, Mon Jun 28 07:29:46 2004 UTC
# Line 175  open-parenthesis, and point ends up at t Line 175  open-parenthesis, and point ends up at t
175  If variable `beginning-of-defun-function' is non-nil, its value  If variable `beginning-of-defun-function' is non-nil, its value
176  is called as a function to find the defun's beginning."  is called as a function to find the defun's beginning."
177    (interactive "p")    (interactive "p")
178      (and (eq this-command 'beginning-of-defun)
179           (or (eq last-command 'beginning-of-defun) (push-mark)))
180    (and (beginning-of-defun-raw arg)    (and (beginning-of-defun-raw arg)
181         (progn (beginning-of-line) t)))         (progn (beginning-of-line) t)))
182    
# Line 223  matches the open-parenthesis that starts Line 225  matches the open-parenthesis that starts
225  If variable `end-of-defun-function' is non-nil, its value  If variable `end-of-defun-function' is non-nil, its value
226  is called as a function to find the defun's end."  is called as a function to find the defun's end."
227    (interactive "p")    (interactive "p")
228      (and (eq this-command 'end-of-defun)
229           (or (eq last-command 'end-of-defun) (push-mark)))
230    (if (or (null arg) (= arg 0)) (setq arg 1))    (if (or (null arg) (= arg 0)) (setq arg 1))
231    (if end-of-defun-function    (if end-of-defun-function
232        (if (> arg 0)        (if (> arg 0)
# Line 277  already marked." Line 281  already marked."
281              (end-of-defun)              (end-of-defun)
282              (point))))              (point))))
283          (t          (t
284           ;; Do it in this order for the sake of languages with nested           (let ((opoint (point))
285           ;; functions where several can end at the same place as with                 beg end)
286           ;; the offside rule, e.g. Python.             (push-mark opoint)
287           (push-mark (point))             ;; Try first in this order for the sake of languages with nested
288           (beginning-of-defun)             ;; functions where several can end at the same place as with
289           (push-mark (point) nil t)             ;; the offside rule, e.g. Python.
290           (end-of-defun)             (beginning-of-defun)
291           (exchange-point-and-mark)             (setq beg (point))
292           (re-search-backward "^\n" (- (point) 1) t))))             (end-of-defun)
293               (setq end (point))
294               (while (looking-at "^\n")
295                 (forward-line 1))
296               (if (> (point) opoint)
297                   (progn
298                     ;; We got the right defun.
299                     (push-mark beg nil t)
300                     (goto-char end)
301                     (exchange-point-and-mark))
302                 ;; beginning-of-defun moved back one defun
303                 ;; so we got the wrong one.
304                 (goto-char opoint)
305                 (end-of-defun)
306                 (push-mark (point) nil t)
307                 (beginning-of-defun))
308               (re-search-backward "^\n" (- (point) 1) t)))))
309    
310  (defun narrow-to-defun (&optional arg)  (defun narrow-to-defun (&optional arg)
311    "Make text outside current defun invisible.    "Make text outside current defun invisible.
# Line 294  Optional ARG is ignored." Line 314  Optional ARG is ignored."
314    (interactive)    (interactive)
315    (save-excursion    (save-excursion
316      (widen)      (widen)
317      ;; Do it in this order for the sake of languages with nested      (let ((opoint (point))
318      ;; functions where several can end at the same place as with the            beg end)
319      ;; offside rule, e.g. Python.        ;; Try first in this order for the sake of languages with nested
320      (beginning-of-defun)        ;; functions where several can end at the same place as with
321      (let ((beg (point)))        ;; the offside rule, e.g. Python.
322          (beginning-of-defun)
323          (setq beg (point))
324        (end-of-defun)        (end-of-defun)
325        (narrow-to-region beg (point)))))        (setq end (point))
326          (while (looking-at "^\n")
327            (forward-line 1))
328          (unless (> (point) opoint)
329            ;; beginning-of-defun moved back one defun
330            ;; so we got the wrong one.
331            (goto-char opoint)
332            (end-of-defun)
333            (setq end (point))
334            (beginning-of-defun)
335            (setq beg (point)))
336          (goto-char end)
337          (re-search-backward "^\n" (- (point) 1) t)
338          (narrow-to-region beg end))))
339    
340    (defvar insert-pair-alist
341      '((?\( ?\)) (?\[ ?\]) (?\{ ?\}) (?\< ?\>) (?\" ?\") (?\' ?\') (?\` ?\'))
342      "Alist of paired characters inserted by `insert-pair'.
343    Each element looks like (OPEN-CHAR CLOSE-CHAR) or (COMMAND-CHAR
344    OPEN-CHAR CLOSE-CHAR).  The characters OPEN-CHAR and CLOSE-CHAR
345    of the pair whose key is equal to the last input character with
346    or without modifiers, are inserted by `insert-pair'.")
347    
348    (defun insert-pair (&optional arg open close)
349      "Enclose following ARG sexps in a pair of OPEN and CLOSE characters.
350    Leave point after the first character.
351    A negative ARG encloses the preceding ARG sexps instead.
352    No argument is equivalent to zero: just insert characters
353    and leave point between.
354    If `parens-require-spaces' is non-nil, this command also inserts a space
355    before and after, depending on the surrounding characters.
356    If region is active, insert enclosing characters at region boundaries.
357    
358  (defun insert-parentheses (arg)  If arguments OPEN and CLOSE are nil, the character pair is found
359    from the variable `insert-pair-alist' according to the last input
360    character with or without modifiers.  If no character pair is
361    found in the variable `insert-pair-alist', then the last input
362    character is inserted ARG times."
363      (interactive "P")
364      (if (not (and open close))
365          (let ((pair (or (assq last-command-char insert-pair-alist)
366                          (assq (event-basic-type last-command-event)
367                                insert-pair-alist))))
368            (if pair
369                (if (nth 2 pair)
370                    (setq open (nth 1 pair) close (nth 2 pair))
371                  (setq open (nth 0 pair) close (nth 1 pair))))))
372      (if (and open close)
373          (if (and transient-mark-mode mark-active)
374              (progn
375                (save-excursion (goto-char (region-end))       (insert close))
376                (save-excursion (goto-char (region-beginning)) (insert open)))
377            (if arg (setq arg (prefix-numeric-value arg))
378              (setq arg 0))
379            (cond ((> arg 0) (skip-chars-forward " \t"))
380                  ((< arg 0) (forward-sexp arg) (setq arg (- arg))))
381            (and parens-require-spaces
382                 (not (bobp))
383                 (memq (char-syntax (preceding-char)) (list ?w ?_ (char-syntax close)))
384                 (insert " "))
385            (insert open)
386            (save-excursion
387              (or (eq arg 0) (forward-sexp arg))
388              (insert close)
389              (and parens-require-spaces
390                   (not (eobp))
391                   (memq (char-syntax (following-char)) (list ?w ?_ (char-syntax open)))
392                   (insert " "))))
393        (insert-char (event-basic-type last-command-event)
394                     (prefix-numeric-value arg))))
395    
396    (defun insert-parentheses (&optional arg)
397    "Enclose following ARG sexps in parentheses.  Leave point after open-paren.    "Enclose following ARG sexps in parentheses.  Leave point after open-paren.
398  A negative ARG encloses the preceding ARG sexps instead.  A negative ARG encloses the preceding ARG sexps instead.
399  No argument is equivalent to zero: just insert `()' and leave point between.  No argument is equivalent to zero: just insert `()' and leave point between.
400  If `parens-require-spaces' is non-nil, this command also inserts a space  If `parens-require-spaces' is non-nil, this command also inserts a space
401  before and after, depending on the surrounding characters."  before and after, depending on the surrounding characters.
402    If region is active, insert enclosing characters at region boundaries."
403    (interactive "P")    (interactive "P")
404    (if arg (setq arg (prefix-numeric-value arg))    (insert-pair arg ?\( ?\)))
405      (setq arg 0))  
406    (cond ((> arg 0) (skip-chars-forward " \t"))  (defun delete-pair ()
407          ((< arg 0) (forward-sexp arg) (setq arg (- arg))))    "Delete a pair of characters enclosing the sexp that follows point."
408    (and parens-require-spaces    (interactive)
409         (not (bobp))    (save-excursion (forward-sexp 1) (delete-char -1))
410         (memq (char-syntax (preceding-char)) '(?w ?_ ?\) ))    (delete-char 1))
411         (insert " "))  
412    (insert ?\()  (defun raise-sexp (&optional arg)
413    (save-excursion    "Raise ARG sexps higher up the tree."
414      (or (eq arg 0) (forward-sexp arg))    (interactive "p")
415      (insert ?\))    (let ((s (if (and transient-mark-mode mark-active)
416      (and parens-require-spaces                 (buffer-substring (region-beginning) (region-end))
417           (not (eobp))               (buffer-substring
418           (memq (char-syntax (following-char)) '(?w ?_ ?\( ))                (point)
419           (insert " "))))                (save-excursion (forward-sexp arg) (point))))))
420        (backward-up-list 1)
421        (delete-region (point) (save-excursion (forward-sexp 1) (point)))
422        (save-excursion (insert s))))
423    
424  (defun move-past-close-and-reindent ()  (defun move-past-close-and-reindent ()
425    "Move past next `)', delete indentation before it, then indent after it."    "Move past next `)', delete indentation before it, then indent after it."

Legend:
Removed from v.1.48.4.1  
changed lines
  Added in v.1.48.4.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26