help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Insert appropriate line-end character (like ';' for C*)


From: David Hansen
Subject: Re: Insert appropriate line-end character (like ';' for C*)
Date: Wed, 11 Jun 2008 22:58:03 +0200
User-agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.0.60 (gnu/linux)

On Wed, 11 Jun 2008 12:09:58 -0700 (PDT) Josh <address@hidden> wrote:

> On Jun 11, 12:17 am, David Hansen <address@hidden> wrote:
>
>> `;' is not a "line-end" character in C but a "end-of-statement"
>> character.  Not even a full featured C parser can know if you want to
>> continue the statement on the next line or not:
>>
>> foo = bar ()
>>         && baz ();
>
> Ok, end of statement is what I was looking for. Thanks.
>
> I know that emacs can't possibly know what my intention is, but it
> _can_ know what the appropriate end-of-statement character is for the
> current context. All I'm looking for is a command that will insert
> that character; I'll take care of making sure it's inserted at the
> appropriate time myself.
>
> To be more clear, I'm trying to replecate a behavior in TextMate. In
> TextMate, if you hit command-shift-return it adds the context-
> appropriate end-of-statement character to the end of the current line,
> creates a new line below it, and indents that new line. I can already
> make Emacs do everything other than insert the end-of-statement
> character, but that's only because I don't know how to programatically
> determine what the correct character is.

Well, set it manually (not tested).  Emacs can not possibly know about
all statement delimiters of all languages out there:

;;; Add more either here or using
;;;   (setq dh-eos-alist (cons '(mode . "str") dh-eos-alist)
(defvar dh-eos-alist '((c-mode    . ";")
                       (c++-mode  . ";")
                       (java-mode . ";")))

(defun dh-insert-eos ()
  (interactive)
  (let ((eos (assq major-mode dh-eos-alist)))
    (insert (if eos
                (cdr eos)
              ""))
    ;; Change this if you don't want auto-indent.
    (newline-and-indent)))

;; May be problematic outside of X.  Use the output of C-h k as an
;; argument to `kbd' for "weird" keys.
(global-set-key (kbd "<S-return>") #'dh-insert-eos)

David





reply via email to

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