I am trying to simplify user input of Pod formatting sequences in cperl-mode. For example, if you type C<hello>, C<> is a Pod formatting sequence for entering code, similar to the use of backticks in Markdown.

The idea is that the user should only have to type C< and then Emacs will ask for the code text and add the ending > followed by as space automatically. Here is an example; for simplicity I have not added the function to cperl-mode-hook yet, so you can test this by doing emacs -Q -l init.el, where init.el is:

(defun my-perl-pod-format-start ()
  "Simplify entering of Pod formatting sequences."
  (let ((char (preceding-char)))
    (insert "<")
    (when (or
           (char-equal char ?C)
           (char-equal char ?I)
           (char-equal char ?B))
      (insert (read-string "Pod formatting code: "))
      (insert "> "))))

(global-set-key (kbd "<") #'my-perl-pod-format-start))

This seems to work fine, but there is at least one drawback: the flow of writing is interrupted, since as soon as the user type the < the focus is moved to the minibuffer. So I wondered, is it possible to do this input (similar to read-string) at the current cursor position (for example like in auto-complete-mode) instead of in the minibuffer?

  • 1
    See function completion-at-point. – Drew Mar 24 '15 at 13:25
  • 2
    Sounds like a job for a yasnippet. – Jordon Biondo Mar 24 '15 at 15:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.