unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: "Lorenzo Isella" <lorenzo.isella@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Problem with keybindings
Date: Fri, 14 Nov 2008 12:57:34 +0100	[thread overview]
Message-ID: <a2b3004b0811140357s31a77847kb3bdaa2f395dcda1@mail.gmail.com> (raw)

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




             reply	other threads:[~2008-11-14 11:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-14 11:57 Lorenzo Isella [this message]
2008-11-14 12:17 ` Problem with keybindings Tassilo Horn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a2b3004b0811140357s31a77847kb3bdaa2f395dcda1@mail.gmail.com \
    --to=lorenzo.isella@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).