[ESS] problems with curly braces { }

Rodney Sparapani rsparapa at mcw.edu
Tue Sep 21 21:51:39 CEST 2010


On 05/27/10 03:22 PM, Rodney Sparapani wrote:
>
> Here's a workaround; use the definition of ess-electric-brace
> below. It works, but it eats the next character. That is
> usually a return and is handled correctly; but, if it's, say a
> semicolon for a comment, then you have to do it twice.

Aha!!!  Now, fixed in SVN.  The problem is the line...
(insert last-command-event)

which needs to be replaced by...
(insert (if (featurep 'xemacs) (event-to-character last-command-event) 
last-command-event))

Here's the new definition...
(defun ess-electric-brace (arg)
   "Insert character and correct line's indentation."
   (interactive "P")
;; skeleton-pair takes precedence
(if (and (boundp 'skeleton-pair) skeleton-pair (featurep 'skeleton))
   (skeleton-pair-insert-maybe "{")
;; else
   (let (insertpos)
     (if (and (not arg)
	     (eolp)
	     (or (save-excursion
		   (skip-chars-backward " \t")
		   (bolp))
		 (if ess-auto-newline (progn (ess-indent-line) (newline) t) nil)))
	(progn
	  (insert (if (featurep 'xemacs) (event-to-character 
last-command-event) last-command-event))
	  (ess-indent-line)
	  (if ess-auto-newline
	      (progn
		(newline)
		;; (newline) may have done auto-fill
		(setq insertpos (- (point) 2))
		(ess-indent-line)))
	  (save-excursion
	    (if insertpos (goto-char (1+ insertpos)))
	    (delete-char -1))))
     (if insertpos
	(save-excursion
	  (goto-char insertpos)
	  (self-insert-command (prefix-numeric-value arg)))
       (self-insert-command (prefix-numeric-value arg))))))

Rodney



More information about the ESS-help mailing list