New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Special characters in heads/docs #126

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

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 closed this in a2f8a23 May 12, 2015

@abo-abo

This comment has been minimized.

Show comment
Hide comment
@abo-abo

abo-abo May 12, 2015

Owner

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

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

This comment has been minimized.

Show comment
Hide comment
@orki

orki 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?

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

This comment has been minimized.

Show comment
Hide comment
@abo-abo

abo-abo May 12, 2015

Owner

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

This comment has been minimized.

Show comment
Hide comment
@orki

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

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 added a commit that referenced this issue May 13, 2015

hydra.el (hydra-fontify-head-default): Add "%" exception
* hydra.el (hydra--hint): Simplify.

Fixes #126
@orki

This comment has been minimized.

Show comment
Hide comment
@orki

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

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