unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Problem with keybindings
@ 2008-11-14 11:57 Lorenzo Isella
  2008-11-14 12:17 ` Tassilo Horn
  0 siblings, 1 reply; 2+ messages in thread
From: Lorenzo Isella @ 2008-11-14 11:57 UTC (permalink / raw)
  To: help-gnu-emacs

Dear All,
I am trying to add a few hooks to my latex mode, but I must be doing
something wrong.
I should say that I am not a elisp programmer, I mainly catch some
bits on the net and try to twist them according to my needs.

Here are the functions


(defun latex-surround-by (empty beg end back-over-end)
  "The main function implementing electric special characters
($, ^,_, etc.; see for example `latex-subscript'). If region is
active, insert BEG before it and END after. Otherwise, insert EMPTY
and place point BACK-OVER-END characters before the end of EMPTY.

If `zmacs-regions' is nil, always behave as if region is *not*
active."
  (if (and zmacs-regions (region-active-p))
      (let ((text (buffer-substring (mark) (point))))
        (delete-region (mark) (point))
        (insert beg)
        (insert text)
        (insert end))
    (progn
      (insert empty)
      (backward-char back-over-end))))






(defun latex-subscript ()
  "Electric subscript.
If region is not active, inserts \"_{}\" and places cursor between
braces.  Otherwise, inserts \"_{\" before region and \"}\"
after. Basically, just a call to `latex-surround-by' with appropriate
arguments."
  (interactive)
  (latex-surround-by "_{}" "_{" "}" 1))

(defun latex-superscript ()
  "Electric superscript.
If region is not active, inserts \"^{}\" and places cursor between
braces.  Otherwise, inserts \"^{\" before region and \"}\"
after. Basically, just a call to `latex-surround-by' with appropriate
arguments."
  (interactive)
  (latex-surround-by "^{}" "^{" "}" 1))


;; LaTeX sectioning search.

(defun latex-next-section ()
  "Moves cursor to the nearest sectioning command below point."
  (interactive)
  (unless (search-forward-regexp
"\\(\\\\\\(sub\\)*section\\)\\|\\(\\\\chapter\\)" nil t)
    (error "No more sectioning commands below.")))

(defun latex-previous-section ()
  "Moves cursor to the nearest sectioning command above point."
  (interactive)
  (unless (search-backward-regexp
"\\(\\\\\\(sub\\)*section\\)\\|\\(\\\\chapter\\)" nil t)
    (error "No more sectioning commands above.")))

and this is how I bind them


;; The actual bindings:

(defun my-latex-bindings ()



  (define-key LaTeX-mode-map  [_] 'latex-subscript)
  (define-key LaTeX-mode-map  [^] 'latex-superscript)


  (define-key LaTeX-mode-map  [(control down)] 'latex-next-section)
  (define-key LaTeX-mode-map  [(control up)] 'latex-previous-section)
)

;; Now I really activate the bindings

(add-hook 'LaTeX-mode-hook 'my-latex-bindings)


However, the function to jump to the previous/next section is
correctly bound, but ^ and _ do not insert e.g. _{}.
Can anyone give me a hint? I looked into my .emacs file and I do not
believe I am re-binding e.g. ^ to anything else.
Many thanks

Lorenzo




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

* Re: Problem with keybindings
  2008-11-14 11:57 Problem with keybindings Lorenzo Isella
@ 2008-11-14 12:17 ` Tassilo Horn
  0 siblings, 0 replies; 2+ messages in thread
From: Tassilo Horn @ 2008-11-14 12:17 UTC (permalink / raw)
  To: help-gnu-emacs

"Lorenzo Isella" <lorenzo.isella@gmail.com> writes:

Hi Lorenzo,

> (defun my-latex-bindings ()
>   (define-key LaTeX-mode-map  [_] 'latex-subscript)
>   (define-key LaTeX-mode-map  [^] 'latex-superscript)

I think the key syntax is wrong.  It's best to always use the `kbd'
function.  There you can enter the keys as they're printed by `C-h k'.

   (define-key LaTeX-mode-map  (kbd "_") 'latex-subscript)
   (define-key LaTeX-mode-map  (kbd "^") 'latex-superscript)


>   (define-key LaTeX-mode-map  [(control down)] 'latex-next-section)
>   (define-key LaTeX-mode-map  [(control up)] 'latex-previous-section)

Although that's the right syntax, I assume that

   (define-key LaTeX-mode-map  (kbd "<C-down>") 'latex-next-section)
   (define-key LaTeX-mode-map  (kbd "<C-up>") 'latex-previous-section)

is a bit easier to read and write.

Bye,
Tassilo
-- 
[Emacs] is written in Lisp, which is the only computer language that is
beautiful.  -- Neal Stephenson, _In the Beginning was the Command Line_





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

end of thread, other threads:[~2008-11-14 12:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-14 11:57 Problem with keybindings Lorenzo Isella
2008-11-14 12:17 ` Tassilo Horn

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