unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Pascal Bourguignon <spam@mouse-potato.com>
Subject: Re: A true challenge for Emac and Elisp hackers - at Least I think so
Date: Wed, 12 Oct 2005 15:48:36 +0200	[thread overview]
Message-ID: <87mzleyhfv.fsf@thalassa.informatimago.com> (raw)
In-Reply-To: 1129117705.959356.9950@g49g2000cwa.googlegroups.com

"Sune" <sune_ahlgren@hotmail.com> writes:
> 1)
> What is listed below is valid for all .c files. Not .h files!
> 2)
> I want RET, the enter key, to trig the following behaviour:
>
>    * If I hit RET with any shift-key being pressed
>      simultaneously, RET must behave as any
>      normal RET would (basically a normal
>      linefeed with possible auto-indentation).
>      This may seem backward but I want almost
>      every line in my sorce to be traceable.
>
>    * If I hit RET only, and the following applies:
>
>        - It is preceeded by a ';' (semicolon) AND the
>          word 'return' is not part of the current
>          line or:
>
>        - It is preceeded by a '{' (curly bracket)
>
>      RET adds DBG after the ';' or the '{' with a
>      space in between like so:
>
>      ; DBG
>      { DBG
>
>      respectively. After that (the same key stroke)
>      , RET behaves like a normal RET would (basically
>      a normal linefeed with possible auto-indentation).
>
> I have to admit that this is so far out there (at least for me) that I
> would need more or less a ready-to-go implementation just to paste into
> .emacs.

This is not a challenge, this is trivial.


(defvar *c-trace-code* " DBG;\n")

(defun c-after (regexp)
  (save-excursion
    (backward-char)
    (while (and (< (point-min) (point)) (looking-at "[\t\n ]"))
      (backward-char))
    (looking-at regexp)))

(defun insert-return-and-trace ()
  (interactive)
    (if (c-after "[{;]")
        (insert *c-trace-code*)
        (insert "\n"))
    (c-indent-command))

(add-hook 'c-mode-hook
          (lambda ()
            (unless (string-match "\\.h$" (buffer-name))
                (local-set-key [return]   (function insert-return-and-trace))
                (local-set-key [S-return] (function newline)))))



> Do you know a place where something similar has been done which I can
> steal and adapt, or are you interested in implementing it? (A place on
> my tomb stone is reserved for anyone that succeeds in doing this)

(info "elisp")


-- 
"You cannot really appreciate Dilbert unless you read it in the
original Klingon"

  parent reply	other threads:[~2005-10-12 13:48 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-12 11:48 A true challenge for Emac and Elisp hackers - at Least I think so Sune
2005-10-12 12:49 ` Gian Uberto Lauri
2005-10-12 13:16 ` Slawomir Nowaczyk
     [not found] ` <mailman.11019.1129123023.20277.help-gnu-emacs@gnu.org>
2005-10-12 13:29   ` Matthieu Moy
2005-10-12 14:04     ` Slawomir Nowaczyk
     [not found]     ` <mailman.11022.1129125880.20277.help-gnu-emacs@gnu.org>
2005-10-12 16:13       ` Giorgos Keramidas
2005-10-12 19:20         ` Chris McMahan
2005-10-12 13:48 ` Pascal Bourguignon [this message]
2005-10-12 15:36 ` Drew Adams
2005-10-12 23:28 ` Thien-Thi Nguyen
2005-10-13  9:13   ` Sune
2005-10-13 14:33     ` Joe Corneli
2005-10-13 21:45   ` Sune
2005-10-13 21:49   ` Sune
2005-10-14 13:10     ` Thien-Thi Nguyen
2005-10-15 17:57   ` Sune
2005-10-15 19:57     ` Thien-Thi Nguyen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87mzleyhfv.fsf@thalassa.informatimago.com \
    --to=spam@mouse-potato.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).