* define-key for a major-mode, 'face and external program
@ 2012-09-08 22:38 pascal chenevas
2012-09-11 15:18 ` pascal chenevas
[not found] ` <mailman.8626.1347376754.855.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 5+ messages in thread
From: pascal chenevas @ 2012-09-08 22:38 UTC (permalink / raw)
To: help-gnu-emacs
[-- Attachment #1.1: Type: text/plain, Size: 1371 bytes --]
Hello,
First of all I would like to say that I'm starting for a week to program in
LIsp and to use Emacs too.
I'm reading such documentation like the emacswiki, the "intoduction to
programming in Emacs Lisp".
For a week I have planed to create a major-mode and from there I can launch
a set of programs.
My major-mode should have a main menu like mu4e.el.
To start with coding I have used the text-mode.el and the source code of
mu4e.
Draft of the main menu:
<center>Welcome Message </center>
<Menu1>General options</Menu1>
[Q] to quit
<Menu2>FTP</Menu2>
[F3] to start
<Menu3>IRC</Menu3>
[F4] to start
Note : The Welcome message should be in blue and the <Menu>text</Menu> in
bold (or in a different color).
My questions are the following:
1) I have tried several set of functions to define a local-map that I can
use for example F2 to run an external program and I still don't understand
why my set of "local keys" are not loaded. I get the error message: <f2> is
undefined.
2) I cannot get working to have a set of 'face to put a text in blue and
the other one in bold.
3) I can run external program with (shell-command "cmd") but I cannot get
Emacs "free" to do anything else I would like (this part is not included in
the source code I have attached).
Attached to the mail you will find the source code I have written.
Many tanks for your help.
Pascal
[-- Attachment #1.2: Type: text/html, Size: 1884 bytes --]
[-- Attachment #2: rct-mode.el --]
[-- Type: application/octet-stream, Size: 2662 bytes --]
;; This file is not part of GNU Emacs.
;;
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;; Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;(require 'rct-util)
;
(defconst rct-mode-buffer-name "*rct-main*"
"*internal* Name of the rct main view buffer.")
; let the user have the possibility to run his hown code
(defcustom rct-mode-hook nil
"Normal hook run when entering Text mode and many related modes."
:type 'hook
:group 'data)
; Keymap
(defvar rct-mode-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-c m")
(lambda() (interactive) (message "C-c m pressed")))
(define-key map (kbd "<f4>")
(lambda() (interactive) (message "<f4> pressed")))
(define-key map (kbd "<f5>")
(lambda() (interactive) (message "<f5> pressed")))
map )
"Keymap for `rct-mode'.")
;; h1 first header in blue
(defface h1
'((t :inherit default
(:background "blue")
))
"Face for a header without any special flags."
:group 'rct-faces)
(define-derived-mode rct-mode special-mode "rct:main"
"Major mode for remote connections
\\{rct-main-mode-map}."
(setq debug-on-error t)
(use-local-map rct-mode-map)
(run-hooks 'rct-mode-hook)
(main-menu))
; Main Menu
(defun main-menu ()
"This function display the main menu of the RCT mode."
(with-current-buffer (get-buffer-create rct-mode-buffer-name)
(erase-buffer)
(insert
"\n\n\n\n"
(propertize "~~ Welcome to the Remote Connection Tool for Emacs ~~" 'face 'h1)
"\n\n"
"Main commands"
"\n\n"
"\t[Q] To quit the RCT-mode"
"\n\n"
"Section 1"
"\n\n"
"\t[F2] To Start XXXX\n"
"\t[F3] To Start YYYYY\n"
"\n"
"Section 2"
"\n\n"
"\t[F4] To Start ZZZZZ\n"
"\n\n"
); end-of insert
);end-of with-current-buffer
;);end-of let
(switch-to-buffer rct-mode-buffer-name)
(toggle-read-only t)
);end-of main-menu
;
(provide 'rct-mode)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: define-key for a major-mode, 'face and external program
2012-09-08 22:38 define-key for a major-mode, 'face and external program pascal chenevas
@ 2012-09-11 15:18 ` pascal chenevas
[not found] ` <mailman.8626.1347376754.855.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 5+ messages in thread
From: pascal chenevas @ 2012-09-11 15:18 UTC (permalink / raw)
To: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 3337 bytes --]
Hello,
can you please help me with the following LISP code?
;(require 'rct-util)
;
(defconst rct-mode-buffer-name "*rct-main*"
"*internal* Name of the rct main view buffer.")
; let the user have the possibility to run his hown code
(defcustom rct-mode-hook nil
"Normal hook run when entering Text mode and many related modes."
:type 'hook
:group 'data)
; Keymap
(defvar rct-mode-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-c m")
(lambda() (interactive) (message "C-c m pressed")))
(define-key map (kbd "<f4>")
(lambda() (interactive) (message "<f4> pressed")))
(define-key map (kbd "<f5>")
(lambda() (interactive) (message "<f5> pressed")))
map )
"Keymap for `rct-mode'.")
;; h1 first header in blue
(defface h1
'((t :inherit default
(:background "blue")
))
"Face for a header without any special flags."
:group 'rct-faces)
(define-derived-mode rct-mode special-mode "rct:main"
"Major mode for remote connections
\\{rct-main-mode-map}."
(setq debug-on-error t)
(use-local-map rct-mode-map)
(run-hooks 'rct-mode-hook)
(main-menu))
; Main Menu
(defun main-menu ()
"This function display the main menu of the RCT mode."
(with-current-buffer (get-buffer-create rct-mode-buffer-name)
(erase-buffer)
(insert
"\n\n\n\n"
(propertize "~~ Welcome ~~" 'face 'h1)
"\n\n"
"Main commands"
"\n\n"
"\t[Q] To quit the RCT-mode"
"\n\n"
"Section 1"
"\n\n"
"\t[F2] To Start XXXX\n"
"\t[F3] To Start YYYYY\n"
"\n"
"Section 2"
"\n\n"
"\t[F4] To Start ZZZZZ\n"
"\n\n"
); end-of insert
);end-of with-current-buffer
;);end-of let
(switch-to-buffer rct-mode-buffer-name)
(toggle-read-only t)
);end-of main-menu
;
(provide 'rct-mode)
Many thanks.
Pascal
2012/9/8 pascal chenevas <pch.netz@gmail.com>
> Hello,
>
> First of all I would like to say that I'm starting for a week to program
> in LIsp and to use Emacs too.
> I'm reading such documentation like the emacswiki, the "intoduction to
> programming in Emacs Lisp".
>
> For a week I have planed to create a major-mode and from there I can
> launch a set of programs.
> My major-mode should have a main menu like mu4e.el.
>
> To start with coding I have used the text-mode.el and the source code of
> mu4e.
>
> Draft of the main menu:
>
> <center>Welcome Message </center>
>
> <Menu1>General options</Menu1>
> [Q] to quit
> <Menu2>FTP</Menu2>
> [F3] to start
> <Menu3>IRC</Menu3>
> [F4] to start
>
> Note : The Welcome message should be in blue and the <Menu>text</Menu> in
> bold (or in a different color).
>
> My questions are the following:
>
> 1) I have tried several set of functions to define a local-map that I can
> use for example F2 to run an external program and I still don't understand
> why my set of "local keys" are not loaded. I get the error message: <f2> is
> undefined.
> 2) I cannot get working to have a set of 'face to put a text in blue and
> the other one in bold.
> 3) I can run external program with (shell-command "cmd") but I cannot get
> Emacs "free" to do anything else I would like (this part is not included in
> the source code I have attached).
>
> Attached to the mail you will find the source code I have written.
>
> Many tanks for your help.
>
> Pascal
>
[-- Attachment #2: Type: text/html, Size: 5469 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
[parent not found: <mailman.8626.1347376754.855.help-gnu-emacs@gnu.org>]
* Re: define-key for a major-mode, 'face and external program
[not found] ` <mailman.8626.1347376754.855.help-gnu-emacs@gnu.org>
@ 2012-09-12 0:45 ` Stefan Monnier
2012-09-12 9:10 ` pascal chenevas
[not found] ` <mailman.8702.1347441052.855.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 5+ messages in thread
From: Stefan Monnier @ 2012-09-12 0:45 UTC (permalink / raw)
To: help-gnu-emacs
> can you please help me with the following LISP code?
Looks fine.
> (define-derived-mode rct-mode special-mode "rct:main"
> "Major mode for remote connections
> \\{rct-main-mode-map}."
> (setq debug-on-error t)
Don't use `setq' in a major-mode since the change will affect
all buffers. Better use (set (make-local-variable 'debug-on-error) t).
> (use-local-map rct-mode-map)
> (run-hooks 'rct-mode-hook)
Don't do that, it's done by `define-derived-mode already.
> (main-menu))
This shouldn't be in the major-mode function, but in another function
(which will probably call the major-mode function).
> (switch-to-buffer rct-mode-buffer-name)
You should probably call pop-to-buffer here instead.
Stefan
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: define-key for a major-mode, 'face and external program
2012-09-12 0:45 ` Stefan Monnier
@ 2012-09-12 9:10 ` pascal chenevas
[not found] ` <mailman.8702.1347441052.855.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 5+ messages in thread
From: pascal chenevas @ 2012-09-12 9:10 UTC (permalink / raw)
To: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 1488 bytes --]
Stefan,
Thank you so much for your answer!
I have corrected my code and now my keys are set !
But now my main menu is not displayed anymore and the hook cannot be added
too.
(defcustom rct-mode-hook nil
"Normal hook run when entering rct mode and many related modes."
:type 'hook
:options '(font-lock-mode t)
:group 'rct)
Actualy I don't know if it's usefull to add the property :options. I get an
error:
Debugger entered--Lisp error: (void-function add-hooks)
(define-derived-mode rct-mode special-mode "rct:main"
(add-hooks 'rct-mode-hook)
)
(defun main()
(main-menu)
(rct-mode)
)
Thank you,
Pascal
2012/9/12 Stefan Monnier <monnier@iro.umontreal.ca>
> > can you please help me with the following LISP code?
>
> Looks fine.
>
> > (define-derived-mode rct-mode special-mode "rct:main"
> > "Major mode for remote connections
> > \\{rct-main-mode-map}."
> > (setq debug-on-error t)
>
> Don't use `setq' in a major-mode since the change will affect
> all buffers. Better use (set (make-local-variable 'debug-on-error) t).
>
> > (use-local-map rct-mode-map)
> > (run-hooks 'rct-mode-hook)
>
> Don't do that, it's done by `define-derived-mode already.
>
> > (main-menu))
>
> This shouldn't be in the major-mode function, but in another function
> (which will probably call the major-mode function).
>
> > (switch-to-buffer rct-mode-buffer-name)
>
> You should probably call pop-to-buffer here instead.
>
>
> Stefan
>
[-- Attachment #2: Type: text/html, Size: 2154 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
[parent not found: <mailman.8702.1347441052.855.help-gnu-emacs@gnu.org>]
* Re: define-key for a major-mode, 'face and external program
[not found] ` <mailman.8702.1347441052.855.help-gnu-emacs@gnu.org>
@ 2012-09-13 3:46 ` Stefan Monnier
0 siblings, 0 replies; 5+ messages in thread
From: Stefan Monnier @ 2012-09-13 3:46 UTC (permalink / raw)
To: help-gnu-emacs
> (defcustom rct-mode-hook nil
> "Normal hook run when entering rct mode and many related modes."
> :type 'hook
> :options '(font-lock-mode t)
> :group 'rct)
> Actualy I don't know if it's usefull to add the property :options.
It's not very useful and `t' is not a valid value there (and
font-lock-mode is enabled by default, so very few people will want to
enable explicitly just for your mode).
BTW, this whole defcustom is unneeded since define-derived-mode already
defines the `rct-mode-hook' for you.
> I get an error:
> Debugger entered--Lisp error: (void-function add-hooks)
The error says you're calling a function that doesn't exist.
> (add-hooks 'rct-mode-hook)
There's `run-hooks' (which you don't need to call since
define-derived-mode does that for you), and there's `add-hook' which
requires one more argument and would be used in the user's .emacs file
rather than in your code.
Stefan
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2012-09-13 3:46 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-08 22:38 define-key for a major-mode, 'face and external program pascal chenevas
2012-09-11 15:18 ` pascal chenevas
[not found] ` <mailman.8626.1347376754.855.help-gnu-emacs@gnu.org>
2012-09-12 0:45 ` Stefan Monnier
2012-09-12 9:10 ` pascal chenevas
[not found] ` <mailman.8702.1347441052.855.help-gnu-emacs@gnu.org>
2012-09-13 3:46 ` Stefan Monnier
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).