Special characters in heads/docs #126

Closed
orki opened this Issue May 12, 2015 · 5 comments

Projects

None yet

2 participants

@orki
orki commented May 12, 2015

The special character % in the last head below and the character ^ in the docstring below are not handled correctly:

  (defhydra hydra-operate-on-number ()
    "Arithmetic operations: + - * /
  Remainder: \\
  Exponent: ^
  Arithmetic shift:< >
  Base conversion: b o x X #
  Choices: "
    ("+" apply-operation-to-number-at-point)
    ("-" apply-operation-to-number-at-point)
    ("*" apply-operation-to-number-at-point)
    ("/" apply-operation-to-number-at-point)
    ("\\" apply-operation-to-number-at-point)
    ("^" apply-operation-to-number-at-point)
    ("<" apply-operation-to-number-at-point)
    (">" apply-operation-to-number-at-point)
    ("b" apply-operation-to-number-at-point :exit t)
    ("o" apply-operation-to-number-at-point :exit t)
    ("x" apply-operation-to-number-at-point :exit t)
    ("X" apply-operation-to-number-at-point :exit t)
    ("#" apply-operation-to-number-at-point :exit t)
    ;; ("%" apply-operation-to-number-at-point :exit t) ; need to file bug report
    )
@abo-abo abo-abo added a commit that closed this issue May 12, 2015
@abo-abo Allow to escape ^ in docstrings
* hydra.el (hydra-deactivate): Fix doc.
(hydra--ignore): Fix doc.
(hydra-amaranth-warn): Add doc.
(hydra--work-around-dedicated): Fix doc.
(hydra--hint): Work around a key being "%".
(hydra--strip-align-markers): New defun.
(hydra--format): Use `hydra--strip-align-markers'.

Fixes #126
a2f8a23
@abo-abo abo-abo closed this in a2f8a23 May 12, 2015
@abo-abo
Owner
abo-abo commented May 12, 2015

You need to modify your code like this:

(defhydra hydra-operate-on-number ()
  "
Arithmetic operations: + - * /
Remainder: \\
Exponent: \\^
Arithmetic shift:< >
Base conversion: b o x X #
Choices: "
  ("+" apply-operation-to-number-at-point)
  ("-" apply-operation-to-number-at-point)
  ("*" apply-operation-to-number-at-point)
  ("/" apply-operation-to-number-at-point)
  ("\\" apply-operation-to-number-at-point)
  ("^" apply-operation-to-number-at-point)
  ("<" apply-operation-to-number-at-point)
  (">" apply-operation-to-number-at-point)
  ("b" apply-operation-to-number-at-point :exit t)
  ("o" apply-operation-to-number-at-point :exit t)
  ("x" apply-operation-to-number-at-point :exit t)
  ("X" apply-operation-to-number-at-point :exit t)
  ("#" apply-operation-to-number-at-point :exit t)
  ("%" apply-operation-to-number-at-point :exit t))

Note the starting newline and the escaping of ^.

@orki
orki commented May 12, 2015

Hmm, ^ in docstrings seem to work, but % as a key still seems to fail with the following error message: Format string ends in middle of format specifier. Note that this error manifests itself only during a call to hydra-operate-on-number/body and not during compilation.

Am I missing something fundamental?

@abo-abo
Owner
abo-abo commented May 12, 2015

Am I missing something fundamental?

Did you forget the newline? I just test this, it works:

(defhydra hydra-zoom (global-map "<f2>")
  "
zoom"
  ("%" text-scale-increase "in")
  ("l" text-scale-decrease "out"))
@orki
orki commented May 13, 2015

I don't think so. Here is the code:

(defhydra hydra-operate-on-number ()
      "
Arithmetic operations: + - * /
Remainder: \\
Exponent: \\^
Arithmetic shift: < >
Base conversion: b o x X #
"
      ("+" apply-operation-to-number-at-point)
      ("-" apply-operation-to-number-at-point)
      ("*" apply-operation-to-number-at-point)
      ("/" apply-operation-to-number-at-point)
      ("\\" apply-operation-to-number-at-point)
      ("^" apply-operation-to-number-at-point)
      ("<" apply-operation-to-number-at-point)
      (">" apply-operation-to-number-at-point)
      ("b" apply-operation-to-number-at-point :exit t)
      ("o" apply-operation-to-number-at-point :exit t)
      ("x" apply-operation-to-number-at-point :exit t)
      ("X" apply-operation-to-number-at-point :exit t)
      ("#" apply-operation-to-number-at-point :exit t)
      ("%" apply-operation-to-number-at-point :exit t)
      )

which pp-macroexpand-last-sexp expands to something containing

(set
   (defvar hydra-operate-on-number/hint nil "Dynamic hint for hydra-operate-on-number.")
   '(concat
     (format "Arithmetic operations: + - * /\nRemainder: \\\nExponent: ^\nArithmetic shift: < >\nBase conversion: b o x X #\n")
     #("+ - * / \\ ^ < > b o x X # %" 0 1
       (face hydra-face-red)
       2 3
       (face hydra-face-red)
       4 5
       (face hydra-face-red)
       6 7
       (face hydra-face-red)
       8 9
       (face hydra-face-red)
       10 11
       (face hydra-face-red)
       12 13
       (face hydra-face-red)
       14 15
       (face hydra-face-red)
       16 17
       (face hydra-face-blue)
       18 19
       (face hydra-face-blue)
       20 21
       (face hydra-face-blue)
       22 23
       (face hydra-face-blue)
       24 25
       (face hydra-face-blue)
       26 27
       (face hydra-face-blue))))

where you can see that the last % is not escaped/doubled.

@abo-abo abo-abo added a commit that referenced this issue May 13, 2015
@abo-abo hydra.el (hydra-fontify-head-default): Add "%" exception
* hydra.el (hydra--hint): Simplify.

Fixes #126
fd8e1b9
@orki
orki commented May 13, 2015

This works, thanks. The only interesting bit is that I added Format: %%%% do the docstring to make it produce a single % in the hint. If I understand correctly, it is because you eval the hint and then send it to message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment