{"action":"opened","issue":{"url":"https://api.github.com/repos/abo-abo/hydra/issues/40","labels_url":"https://api.github.com/repos/abo-abo/hydra/issues/40/labels{/name}","comments_url":"https://api.github.com/repos/abo-abo/hydra/issues/40/comments","events_url":"https://api.github.com/repos/abo-abo/hydra/issues/40/events","html_url":"https://github.com/abo-abo/hydra/issues/40","id":58409105,"number":40,"title":"Programmatically creating hydras?","user":{"login":"joostkremers","id":191630,"avatar_url":"https://avatars.githubusercontent.com/u/191630?v=3","gravatar_id":"","url":"https://api.github.com/users/joostkremers","html_url":"https://github.com/joostkremers","followers_url":"https://api.github.com/users/joostkremers/followers","following_url":"https://api.github.com/users/joostkremers/following{/other_user}","gists_url":"https://api.github.com/users/joostkremers/gists{/gist_id}","starred_url":"https://api.github.com/users/joostkremers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joostkremers/subscriptions","organizations_url":"https://api.github.com/users/joostkremers/orgs","repos_url":"https://api.github.com/users/joostkremers/repos","events_url":"https://api.github.com/users/joostkremers/events{/privacy}","received_events_url":"https://api.github.com/users/joostkremers/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-02-20T20:55:21Z","updated_at":"2015-02-20T20:55:21Z","closed_at":null,"body":"Following up on http://oremacs.com/2015/02/19/hydra-colors-reloaded/#comment-1866197495\r\n\r\nI post the example code below, but to get to the point quickly: It probably wouldn’t be difficult to write a macro that generates a call to `defhydra` based on some the contents of `pandoc--binary-options`. The problem is that I would like to have a nice menu like the ones generated by the new doc string but that the number of rows and columns in which the hydra’s heads are presented can’t be determined in advance. If the frame is wide, there can be more columns and fewer rows, if it is narrower, there will need to be more rows and fewer columns.\r\n\r\nAnyway, to see what I do with the menus: the code creating the menu in `pandoc-mode` is here:\r\n\r\nhttps://github.com/joostkremers/pandoc-mode/blob/master/pandoc-mode.el#L1522\r\n\r\nAs an example, I have an alist `pandoc--binary-options` which contains conses of the form `(<descr> . <option>)`. `<descr>` is a string that will appear in the menu, `<option>` is a symbol that is used internally to keep track of the option’s value. Using this alist, I create a submenu with the following code in`easy-menu-define` (starting at line 1613):\r\n\r\n```\r\n(\"Switches\"\r\n     ;; put the binary options into the menu\r\n     ,@(mapcar (lambda (option)\r\n                 (vector (car option) `(pandoc--toggle (quote ,(cdr option)))\r\n                         :active t\r\n                         :style 'toggle\r\n                         :selected `(pandoc--get (quote ,(cdr option)))))\r\n               pandoc--binary-options))\r\n```\r\n\r\nThe alist `pandoc--binary-options` is populated by a macro `pandoc-define-binary-option`, which takes `<descr>` and `<option>` as arguments (and does a few other things as well). This way, when Pandoc adds a new option, I only need to add a single line to `pandoc-mode.el`, everything else is generated automatically.\r\n"}}