[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Problem with keybindings
From: |
Lorenzo Isella |
Subject: |
Problem with keybindings |
Date: |
Fri, 14 Nov 2008 12:57:34 +0100 |
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
- Problem with keybindings,
Lorenzo Isella <=