unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* defining my own newline function
@ 2007-11-06  4:28 Ryan Krauss
  2007-11-06  5:43 ` Drew Adams
  0 siblings, 1 reply; 5+ messages in thread
From: Ryan Krauss @ 2007-11-06  4:28 UTC (permalink / raw)
  To: help-gnu-emacs


[-- Attachment #1.1: Type: text/plain, Size: 1205 bytes --]

I am writing my first major mode and in many ways it is going well.  As one
of the last steps, I want to write my own newline-and-indent function.  I am
having trouble getting my function called when I press return.  I have the
following in my local keymap for the mode:

(define-key pypoutline-mode-map "\C-j" 'pypoutline-newline-and-indent)
    (define-key pypoutline-mode-map [<return>]
'pypoutline-newline-and-indent)
    (define-key py-mode-map "\C-m" 'pypoutline-newline-and-indent)

but none of them seem to be working.  If I type C-h k and then hit return
(in a buffer running my mode), I get:

RET (translated from <return>) runs the command newline
  which is an interactive compiled Lisp function in `simple.el'.
It is bound to RET.
(newline &optional arg)

Insert a newline, and move to left margin of the new line if it's blank.
If `use-hard-newlines' is non-nil, the newline is marked with the
text-property `hard'.
With arg, insert that many newlines.
Call `auto-fill-function' if the current column number is greater
than the value of `fill-column' and arg is nil.


What am I doing wrong?  Is there something I need to add to the syntax table
of my mode or somewhere else?

Thanks,

Ryan

[-- Attachment #1.2: Type: text/html, Size: 1421 bytes --]

[-- Attachment #2: Type: text/plain, Size: 152 bytes --]

_______________________________________________
help-gnu-emacs mailing list
help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: defining my own newline function
  2007-11-06  4:28 defining my own newline function Ryan Krauss
@ 2007-11-06  5:43 ` Drew Adams
  2007-11-06 13:56   ` Ryan Krauss
  0 siblings, 1 reply; 5+ messages in thread
From: Drew Adams @ 2007-11-06  5:43 UTC (permalink / raw)
  To: Ryan Krauss, help-gnu-emacs

> (define-key pypoutline-mode-map "\C-j" 'pypoutline-newline-and-indent)
> (define-key pypoutline-mode-map [<return>] 'pypoutline-newline-and-indent)
> (define-key py-mode-map "\C-m" 'pypoutline-newline-and-indent)

> but none of them seem to be working.  If I type C-h k and
> then hit return (in a buffer running my mode), I get:

> RET (translated from <return>) runs the command newline

> What am I doing wrong?  Is there something I need to add
> to the syntax table of my mode or somewhere else?

Are you sure that you are in your mode and that your mode has your mode map
as its local map? What does `M-: (current-local-mode)' tell you?

[BTW, it's generally better to use plain text, not HTML, for email to a
mailing list.]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: defining my own newline function
  2007-11-06  5:43 ` Drew Adams
@ 2007-11-06 13:56   ` Ryan Krauss
  2007-11-06 14:25     ` Ryan Krauss
  0 siblings, 1 reply; 5+ messages in thread
From: Ryan Krauss @ 2007-11-06 13:56 UTC (permalink / raw)
  To: help-gnu-emacs

Sorry, I meant to cc the list as well.

I can't  make 'M-: (current-local-mode)' do anything.  I assume you
want me to press Alt-Shift-: (the shift is needed to make a colon
rather than a semi-colon?).  When I do that, I prompted with
Eval:

so, I typed
(current-local-mode)

there and I get

Debugger entered--Lisp error: (void-function current-local-mode)
 (current-local-mode)
 eval((current-local-mode))
 eval-expression((current-local-mode) nil)
 call-interactively(eval-expression)


But the info line lists my major mode as the one being run.  The
syntax highlighting is what I have defined, and my indent function is
being used.  My local key map is also available, with an outdent
function bound to backtab.  These keys don't work if I create a .txt
file where my mode isn't running.  So, I think my mode is running and
my local key map is happening with other keys.

Ryan

On 11/5/07, Drew Adams <drew.adams@oracle.com> wrote:
> > (define-key pypoutline-mode-map "\C-j" 'pypoutline-newline-and-indent)
> > (define-key pypoutline-mode-map [<return>] 'pypoutline-newline-and-indent)
> > (define-key py-mode-map "\C-m" 'pypoutline-newline-and-indent)
>
> > but none of them seem to be working.  If I type C-h k and
> > then hit return (in a buffer running my mode), I get:
>
> > RET (translated from <return>) runs the command newline
>
> > What am I doing wrong?  Is there something I need to add
> > to the syntax table of my mode or somewhere else?
>
> Are you sure that you are in your mode and that your mode has your mode map
> as its local map? What does `M-: (current-local-mode)' tell you?
>
> [BTW, it's generally better to use plain text, not HTML, for email to a
> mailing list.]
>
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: defining my own newline function
  2007-11-06 13:56   ` Ryan Krauss
@ 2007-11-06 14:25     ` Ryan Krauss
  0 siblings, 0 replies; 5+ messages in thread
From: Ryan Krauss @ 2007-11-06 14:25 UTC (permalink / raw)
  To: help-gnu-emacs

On 11/6/07, Ryan Krauss <ryanlists@gmail.com> wrote:
> Sorry, I meant to cc the list as well.
>
> I can't  make 'M-: (current-local-mode)' do anything.  I assume you
> want me to press Alt-Shift-: (the shift is needed to make a colon
> rather than a semi-colon?).  When I do that, I prompted with
> Eval:
>
> so, I typed
> (current-local-mode)
>
> there and I get
>
> Debugger entered--Lisp error: (void-function current-local-mode)
>  (current-local-mode)
>  eval((current-local-mode))
>  eval-expression((current-local-mode) nil)
>  call-interactively(eval-expression)
>
>
> But the info line lists my major mode as the one being run.  The
> syntax highlighting is what I have defined, and my indent function is
> being used.  My local key map is also available, with an outdent
> function bound to backtab.  These keys don't work if I create a .txt
> file where my mode isn't running.  So, I think my mode is running and
> my local key map is happening with other keys.
>
> Ryan
>
> On 11/5/07, Drew Adams <drew.adams@oracle.com> wrote:
> > > (define-key pypoutline-mode-map "\C-j" 'pypoutline-newline-and-indent)
> > > (define-key pypoutline-mode-map [<return>] 'pypoutline-newline-and-indent)
> > > (define-key py-mode-map "\C-m" 'pypoutline-newline-and-indent)
> >
> > > but none of them seem to be working.  If I type C-h k and
> > > then hit return (in a buffer running my mode), I get:
> >
> > > RET (translated from <return>) runs the command newline
> >
> > > What am I doing wrong?  Is there something I need to add
> > > to the syntax table of my mode or somewhere else?
> >
> > Are you sure that you are in your mode and that your mode has your mode map
> > as its local map? What does `M-: (current-local-mode)' tell you?
> >
> > [BTW, it's generally better to use plain text, not HTML, for email to a
> > mailing list.]
> >
> >
>


So, I found the solution to my problem.  In trying to figure out what
key combination I needed to bind in my local map, I copied and pasted
from python-mode:

(define-key py-mode-map "\C-m" 'pypoutline-newline-and-indent)

I changed the name of the function, but not the name of the map.

Apparently, "\C-m" is the right one for my settings, but I forgot to
change which mode I wanted that key mapped in.  I discovered this when
I got strange behavior while trying to edit a python file.  Changing
the last line to

(define-key pypoutline-mode-map "\C-m" 'pypoutline-newline-and-indent)

fixed my issue.

Ryan

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: defining my own newline function
       [not found] <c5b438120711060533s4813d551s947e036870206514@mail.gmail.com>
@ 2007-11-06 14:29 ` Drew Adams
  0 siblings, 0 replies; 5+ messages in thread
From: Drew Adams @ 2007-11-06 14:29 UTC (permalink / raw)
  To: Ryan Krauss; +Cc: Help-Gnu-Emacs

> I can't  make 'M-: (current-local-mode)' do anything.  I assume you
> want me to press Alt-Shift-: (the shift is needed to make a colon
> rather than a semi-colon?).  When I do that, I prompted with
> Eval:
>
> so, I typed (current-local-mode) there and I get
>
> Debugger entered--Lisp error: (void-function current-local-mode)
>   (current-local-mode)
>   eval((current-local-mode))
>   eval-expression((current-local-mode) nil)
>   call-interactively(eval-expression)
>
> But the info line lists my major mode as the one being run.  The
> syntax highlighting is what I have defined, and my indent function is
> being used.  My local key map is also available, with an outdent
> function bound to backtab.  These keys don't work if I create a .txt
> file where my mode isn't running.  So, I think my mode is running and
> my local key map is happening with other keys.

You did it right. Sorry, I meant `current-local-map'. But that won't help
much. To check the current mode, just do `C-h v major-mode' - that's what I
should have said.

You can also do `M-x pp-eval-expression RET (current-local-map)'. That will
show you the keymap for the current mode, but in the form of a list. If you
don't recognize your keys there, then the map is not what you expect.

My questions were meant only as a quick sanity check - to make sure that you
did in fact enter your mode and that your mode does in fact use the map you
expect. HTH.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-11-06 14:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-06  4:28 defining my own newline function Ryan Krauss
2007-11-06  5:43 ` Drew Adams
2007-11-06 13:56   ` Ryan Krauss
2007-11-06 14:25     ` Ryan Krauss
     [not found] <c5b438120711060533s4813d551s947e036870206514@mail.gmail.com>
2007-11-06 14:29 ` Drew Adams

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).