unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Redefining the TAB key in a custom major mode:
@ 2016-01-10  2:22 Davin Pearson
  2016-01-10  2:27 ` Dmitry Gutov
  0 siblings, 1 reply; 2+ messages in thread
From: Davin Pearson @ 2016-01-10  2:22 UTC (permalink / raw)
  To: help-gnu-emacs


(defun c2j-mode ()
  (interactive)
  (java-mode)
  (setq major-mode 'c2j-mode)
  (setq mode-name "C2J Mode")
  (setq c2j-mode-map (copy-keymap java-mode-map))
  (assert (fboundp 'd-indent-line))
  (setcdr (assq 9 c2j-mode-map) 'd-indent-line) ;; won't work under XEmacs
  (define-key c2j-mode-map [tab] 'd-indent-line)
  (define-key c2j-mode-map [(tab)] 'd-indent-line)
  (define-key c2j-mode-map "\t" 'd-indent-line)
  )

With the previous function defined C-h v TAB returns the following
information:

<tab> runs the command indent-for-tab-command

None of the previous four lines seem to redefine the TAB key to my
custom function d-indent-line.



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

* Re: Redefining the TAB key in a custom major mode:
  2016-01-10  2:22 Redefining the TAB key in a custom major mode: Davin Pearson
@ 2016-01-10  2:27 ` Dmitry Gutov
  0 siblings, 0 replies; 2+ messages in thread
From: Dmitry Gutov @ 2016-01-10  2:27 UTC (permalink / raw)
  To: Davin Pearson, help-gnu-emacs

On 01/10/2016 05:22 AM, Davin Pearson wrote:
>
> (defun c2j-mode ()
>    (interactive)
>    (java-mode)
>    (setq major-mode 'c2j-mode)
>    (setq mode-name "C2J Mode")
>    (setq c2j-mode-map (copy-keymap java-mode-map))
>    (assert (fboundp 'd-indent-line))
>    (setcdr (assq 9 c2j-mode-map) 'd-indent-line) ;; won't work under XEmacs
>    (define-key c2j-mode-map [tab] 'd-indent-line)
>    (define-key c2j-mode-map [(tab)] 'd-indent-line)
>    (define-key c2j-mode-map "\t" 'd-indent-line)
>    )

You seem to be missing the line that would make cj2-mode-map the current 
keymap. Call use-local-map?

But you probably should use the handly macro called define-derived-mode, 
instead of setting this stuff up manually.



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

end of thread, other threads:[~2016-01-10  2:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-10  2:22 Redefining the TAB key in a custom major mode: Davin Pearson
2016-01-10  2:27 ` Dmitry Gutov

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