From 0afc638e16b810467214dbf8ccb22dedf03791d0 Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Sat, 17 Feb 2018 17:19:52 -0500 Subject: [PATCH 1/4] Fix docs for new org mode * Rakefile: Comment to remind me how to run it. * doc/snippet-expansion.org: * doc/snippet-menu.org: It seems org 9.x got a bit stricter about link formatting. Cross-file links *must* use the 'file:' prefix. * doc/yas-doc-helper.el (yas--document-symbol): Org 9.x also got a bit more strict about empty lines between a node and its property list. Make sure not to put a blank line between variable nodes and the property list. --- Rakefile | 4 ++++ doc/snippet-expansion.org | 6 +++--- doc/snippet-menu.org | 2 +- doc/snippet-organization.org | 2 +- doc/yas-doc-helper.el | 4 ++-- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Rakefile b/Rakefile index 83c6257..c63d269 100644 --- a/Rakefile +++ b/Rakefile @@ -50,6 +50,10 @@ task :release => [:package, 'doc:archive'] do raise "Not implemented for github yet!" end +# rake doc[../htmlize] +# +# To do this interactively, load doc/yas-doc-helper, open one of the +# org files, and do `C-c C-e P'. desc "Generate document" task :doc, [:htmlize] do |t, args| load_path = '-L .' diff --git a/doc/snippet-expansion.org b/doc/snippet-expansion.org index a14ce15..f0fa029 100644 --- a/doc/snippet-expansion.org +++ b/doc/snippet-expansion.org @@ -77,7 +77,7 @@ obsolete. ** Insert at point -The command [[#yas-insert-snippet][=yas-insert-snippet=]] lets you insert snippets at point +The command [[sym:yas-insert-snippet][=yas-insert-snippet=]] lets you insert snippets at point /for your current major mode/. It prompts you for the snippet key first, and then for a snippet template if more than one template exists for the same key. @@ -94,7 +94,7 @@ The prompting methods used are again controlled by It's often useful to inject already written text in the middle of a snippet. The variable [[sym:yas-wrap-around-region][=yas-wrap-around-region=]] when to t substitute the region contents into the =$0= placeholder of a snippet expanded by -[[#yas-insert-snippet][=yas-insert-snippet=]]. Setting it to a character value (e.g. =?0=) +[[sym:yas-insert-snippet][=yas-insert-snippet=]]. Setting it to a character value (e.g. =?0=) will insert the contents of corresponding register. Older (versions 0.9.1 and below) of Yasnippet, supported a setting of @@ -169,7 +169,7 @@ In particular, the following things matter: - Buffer-local list of extra modes - Use [[#yas-activate-extra-mode][=yas-activate-extra-mode=]] to + Use [[sym:yas-activate-extra-mode][=yas-activate-extra-mode=]] to consider snippet tables whose name does not correspond to a major mode. Typically, you call this from a minor mode hook, for example: diff --git a/doc/snippet-menu.org b/doc/snippet-menu.org index 272ea16..fee3a19 100644 --- a/doc/snippet-menu.org +++ b/doc/snippet-menu.org @@ -24,7 +24,7 @@ In this menu, you can find Invoking "Load snippets..." from the menu invokes [[sym:yas-load-directory][=yas-load-directory=]] and prompts you for a snippet directory hierarchy to load. -Also useful is the "Reload everything" item to invoke [[#yas-reload-all][=yas-reload-all=]] +Also useful is the "Reload everything" item to invoke [[sym:yas-reload-all][=yas-reload-all=]] which uncondionally reloads all the snippets directories defined in [[sym:yas-snippet-dirs][=yas-snippet-dirs=]] and rebuilds the menus. diff --git a/doc/snippet-organization.org b/doc/snippet-organization.org index 746cff0..dc49249 100644 --- a/doc/snippet-organization.org +++ b/doc/snippet-organization.org @@ -81,7 +81,7 @@ If you place an empty plain text file =.yas-make-groups= inside one of the mode directories, the names of these sub-directories are - considered groups of snippets and [[snippet-menu.org][the menu]] is organized much more + considered groups of snippets and [[file:snippet-menu.org][the menu]] is organized much more cleanly: [[./images/menu-groups.png]] diff --git a/doc/yas-doc-helper.el b/doc/yas-doc-helper.el index e272e41..8fbee8e 100644 --- a/doc/yas-doc-helper.el +++ b/doc/yas-doc-helper.el @@ -45,7 +45,7 @@ (mapcar #'symbol-name (help-function-arglist symbol t)))) (heading (cond ((fboundp symbol) (format - "%s =%s= (%s)" stars symbol + "%s =%s= (%s)\n" stars symbol (mapconcat (lambda (a) (format (if (string-prefix-p "&" a) "/%s/" "=%s=") a)) @@ -91,7 +91,7 @@ (format "=%s=" name)))) body t)) ;; output the paragraph - (concat heading "\n" after-heading "\n" body))) + (concat heading after-heading "\n" body))) (defun yas--document-symbols (level &rest names-and-predicates) (let ((sym-lists (make-vector (length names-and-predicates) nil)) From e261832b1ab17a98cd2b5b706d7bf657589abfe0 Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Sat, 17 Feb 2018 19:55:36 -0500 Subject: [PATCH 2/4] Add some styling to doc, improve top menu * doc/snippet-expansion.org: * doc/snippet-organization.org: Fix typos. * doc/stylesheets/manual.css: Add some simple styling. Mainly, this sets 'max-width' for the main text, and centers it. Adjust the background color. * doc/nav-menu.html.inc: Adjust 'class' of top menu. * doc/yas-doc-helper.el (yas--make-preamble): New function, used for :html-preamble. It sets the element for the current page in the top menu as bolded text to aid navigation. * doc/stylesheets/styles.css: Remove, it was unused since the old rst manual was removed. --- doc/nav-menu.html.inc | 4 +- doc/snippet-expansion.org | 2 +- doc/snippet-organization.org | 5 +- doc/stylesheets/manual.css | 33 ++++++++----- doc/stylesheets/styles.css | 93 ------------------------------------ doc/yas-doc-helper.el | 22 +++++++-- 6 files changed, 46 insertions(+), 113 deletions(-) delete mode 100644 doc/stylesheets/styles.css diff --git a/doc/nav-menu.html.inc b/doc/nav-menu.html.inc index 2a3f0a1..3e74cf8 100644 --- a/doc/nav-menu.html.inc +++ b/doc/nav-menu.html.inc @@ -3,8 +3,8 @@
  • Overview
  • Intro and Tutorial -
  • Snippet -
      +
    • Snippet +
      • Organization
      • Expansion
      • Development diff --git a/doc/snippet-expansion.org b/doc/snippet-expansion.org index f0fa029..a699d57 100644 --- a/doc/snippet-expansion.org +++ b/doc/snippet-expansion.org @@ -21,7 +21,7 @@ - Using hippie-expand - - Call [[sym:yas-insert-snippet][=yas-insert-snippet=]] (use =M-x yas-insert-snippet== or its + - Call [[sym:yas-insert-snippet][=yas-insert-snippet=]] (use =M-x yas-insert-snippet= or its keybinding =C-c & C-s=). - Use m2m's excellent auto-complete diff --git a/doc/snippet-organization.org b/doc/snippet-organization.org index dc49249..22d3e46 100644 --- a/doc/snippet-organization.org +++ b/doc/snippet-organization.org @@ -4,8 +4,9 @@ * Basic structure - Snippet collections can be stored in plain text files. They are arranged by - sub-directories naming *snippet tables*. These mostly name Emacs major names. + Snippet collections can be stored in plain text files. They are + arranged by sub-directories naming *snippet tables*. These mostly + name Emacs major mode names. #+begin_example . diff --git a/doc/stylesheets/manual.css b/doc/stylesheets/manual.css index 9580347..74bfe16 100644 --- a/doc/stylesheets/manual.css +++ b/doc/stylesheets/manual.css @@ -1,5 +1,14 @@ -nav > ul > li.center > ul { - padding: 0; +.center { margin-left: auto; margin-right: auto; text-align: center; } +.current { + font-weight: bold; + background-color: #E0E8F0; +} + +body { background-color: #E4F0F4 } +div#content { + max-width: 20cm; + margin-left: auto; + margin-right: auto; } nav li { @@ -9,20 +18,22 @@ nav li { list-style-type: none; padding: 0.5em; } - nav > ul > li { display: inline-block; } - -/* match org's css for
         */
        -code {
        -    background-color: #F3F5F7;
        -    font-family: courier, monospace;
        +.nopad {
        +    padding: 0;
        +}
        +li.border {
        +    border: solid;
        +    border-width: 1px;
         }
         
        -#content {
        -    margin-left: 5%;
        -    margin-right: 10%;
        +pre, code{ background-color: #F3F5F7; }
        +code {
        +    /* http://neugierig.org/software/chromium/notes/2009/09/monospace-fonts-workaround.html */
        +    font-family: WorkAroundWebKitAndMozilla, monospace;
        +    white-space: nowrap;
         }
         
         /* Styles for htmlize.el fontification.  */
        diff --git a/doc/stylesheets/styles.css b/doc/stylesheets/styles.css
        deleted file mode 100644
        index a158012..0000000
        --- a/doc/stylesheets/styles.css
        +++ /dev/null
        @@ -1,93 +0,0 @@
        -@media all
        -{
        -    body {
        -        margin: 1em auto;
        -        /*margin: 10px 18% 10px 18%;*/
        -        font-family: Arial;
        -        /*text-align: justify;*/
        -        font-size: 14pt;
        -        padding: 10px;
        -        line-height: 1.2em;
        -        max-width: 600pt;
        -    }
        -
        -    div#table-of-contents {
        -        position: fixed;
        -        left: 0%;
        -        right: 0%;
        -        top: 0px;
        -        z-index: 100;
        -        background: black;
        -    }
        -
        -    div#table-of-contents h2 {
        -        display: none;
        -    }
        -
        -    div#table-of-contents a {
        -        text-decoration: none;
        -        color: white;
        -    }
        -
        -    div#table-of-contents a:visited {
        -        color: white;
        -    }
        -
        -    div#table-of-contents a:hover {
        -        color: orange;
        -    }
        -
        -    div.outline-2 h2{
        -        padding-top: 50px;
        -    }
        -
        -    div#text-table-of-contents {
        -        text-color: white;
        -        text-align: center;
        -        margin-left: 30%;
        -        margin-right: 30%;
        -    }
        -
        -    div#text-table-of-contents ul {
        -        height: 2em;
        -        width: 500px;
        -        list-style: none;
        -        margin: auto;
        -    }
        -
        -    div#text-table-of-contents ul li {
        -        float: left;
        -        margin-left:auto;
        -        margin-right: auto;
        -        padding-left: 10px;
        -    }
        -
        -    div#postamble{
        -        position: fixed;
        -        width: 800px;
        -        height: 250px;
        -        left: 50%;
        -        right: 50%;
        -        margin:-75px 0 0 -400px;
        -        bottom: -20px;
        -        font-size: 10pt;
        -        color: grey;
        -        background: url('siscog-bottom-logo.png') no-repeat;
        -        /* background-size: 100% 100%; */
        -    }
        -
        -    div#postamble *{
        -        display: none;
        -    }
        -
        -    div#postamble p.date{
        -        position: relative;
        -        bottom: -200px;
        -        text-align: center;
        -        display: block;
        -    }
        -
        -
        -
        -
        -}
        \ No newline at end of file
        diff --git a/doc/yas-doc-helper.el b/doc/yas-doc-helper.el
        index 8fbee8e..00b2d00 100644
        --- a/doc/yas-doc-helper.el
        +++ b/doc/yas-doc-helper.el
        @@ -118,6 +118,22 @@
         ;; This lets all the org files be exported to HTML with
         ;; `org-publish-current-project' (C-c C-e P).
         
        +(defun yas--make-preamble (props)
        +  "Return contents of nav-menu-html.inc.
        +But replace link to \"current\" page with a span element."
        +  (with-temp-buffer
        +    (let ((dir (file-name-directory (plist-get props :input-file))))
        +      (insert-file-contents (expand-file-name "nav-menu.html.inc" dir))
        +      (goto-char (point-min))
        +      (search-forward (concat ""))
        +      (replace-match "")
        +      (search-forward "")
        +      (replace-match "")
        +      (buffer-string))))
        +
         (let* ((dir (if load-file-name (file-name-directory load-file-name)
                       default-directory))
                (src-epoch (getenv "SOURCE_DATE_EPOCH"))
        @@ -138,10 +154,8 @@
                 `(,@(when (fboundp 'org-html-publish-to-html)
                       '(:publishing-function org-html-publish-to-html))
                   :base-directory ,dir :publishing-directory ,dir
        -          :html-preamble
        -          ,(with-temp-buffer
        -             (insert-file-contents (expand-file-name "nav-menu.html.inc" dir))
        -             (buffer-string))
        +          :html-preamble yas--make-preamble
        +          ;;:with-broken-links mark
                   :html-postamble
                   ,(concat "

        Generated by %c from " (or rev yas--version) " " date "

        \n" From 3032337831cf466e80578c0161e6de660263ed9b Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Sun, 18 Feb 2018 07:20:34 -0500 Subject: [PATCH 3/4] Improve rendering of docstrings in manual's reference section * doc/yas-doc-helper.el (yas--org-raw-html): Accept an ATTRS argument. (yas--document-symbol): Render variables with ... instead of =...=. Render indented lisp forms (recognized as lines beginning 4+ spaces followed by open paren) with #+BEGIN_SRC elisp...#+END_SRC. Render \\{keymap} with substitute-command-keys and #+BEGIN_EXAMPOE...#+END_EXAMPLE. Link "Info node `(manul) Node Name'" to gnu.org manual page. * yasnippet.el (yas-prompt-functions): Add spaces to make example lisp form be recognized as lisp. --- doc/yas-doc-helper.el | 54 +++++++++++++++++++++++++++++++++++-------- yasnippet.el | 2 +- 2 files changed, 46 insertions(+), 10 deletions(-) diff --git a/doc/yas-doc-helper.el b/doc/yas-doc-helper.el index 00b2d00..f48628f 100644 --- a/doc/yas-doc-helper.el +++ b/doc/yas-doc-helper.el @@ -31,13 +31,14 @@ (require 'ox-publish)) (require 'yasnippet) ; docstrings must be loaded -(defun yas--org-raw-html (tag content) +(defun yas--org-raw-html (tag content &optional attrs) ;; in version 8.0 org-mode changed the export syntax, see ;; http://orgmode.org/worg/org-8.0.html#sec-8-1 (format (if (version< org-version "8.0.0") "@<%s>%s@" ; old: @ "@@html:<%s>@@%s@@html:@@") ; new: @@html:@@ - tag content tag)) + (concat tag (if attrs " ") attrs) + content tag)) (defun yas--document-symbol (symbol level) (let* ((stars (make-string level ?*)) @@ -45,14 +46,17 @@ (mapcar #'symbol-name (help-function-arglist symbol t)))) (heading (cond ((fboundp symbol) (format - "%s =%s= (%s)\n" stars symbol + "%s %s (%s)\n" stars (yas--org-raw-html "code" symbol "class='function'") (mapconcat (lambda (a) (format (if (string-prefix-p "&" a) - "/%s/" "=%s=") a)) + "/%s/" "=%s=") + a)) args " "))) (t - (format "%s =%s=\n" stars symbol)))) + (format "%s %s\n" stars + (yas--org-raw-html "code" symbol "class='variable'"))))) (after-heading (format ":PROPERTIES:\n:CUSTOM_ID: %s\n:END:" symbol)) + (text-quoting-style 'grave) (body (or (cond ((fboundp symbol) (let ((doc-synth (car-safe (get symbol 'function-documentation)))) (if (functionp doc-synth) @@ -64,10 +68,17 @@ (format "*WARNING*: no symbol named =%s=" symbol))) (format "*WARNING*: no doc for symbol =%s=" symbol))) (case-fold-search nil)) - ;; do some transformations on the body: + ;; Do some transformations on the body: ;; ARGxxx becomes @arg@xxx ;; FOO becomes /foo/ ;; `bar' becomes [[#bar][=bar=]] + ;; (...) becomes #+BEGIN_SRC elisp (...) #+END_SRC + ;; Info node `(some-manual) Node Name' becomes + ;; [[https://www.gnu.org/software/emacs/manual/html_node/some-manual/Node-Name.html] + ;; [(some-manual) Node Name]] + ;; + ;; This is fairly fragile, though it seems to be working for + ;; now... (setq body (replace-regexp-in-string "\\<\\([A-Z][-A-Z0-9]+\\)\\(\\sw+\\)?\\>" #'(lambda (match) @@ -82,14 +93,39 @@ match1))) body t t 1) body (replace-regexp-in-string - "`\\([a-z-]+\\)'" + "\\\\{[^}]+}" + (lambda (match) + (concat "#+BEGIN_EXAMPLE\n" + (substitute-command-keys match) + "#+END_EXAMPLE\n")) + body t t) + body (substitute-command-keys body) + body (replace-regexp-in-string + "Info node `(\\([-a-z]+\\)) \\([A-Za-z0-9 ]+\\)'" + (lambda (match) + (let* ((manual (match-string 1 match)) + (node (match-string 2 match)) + (html-node (replace-regexp-in-string " " "-" node t t))) + (format "Info node\ + [[https://www.gnu.org/software/emacs/manual/html_node/%s/%s.html][(%s) %s]]" + manual html-node manual node))) + body t t) + body (replace-regexp-in-string + "`\\([-a-z]+\\)'" #'(lambda (match) (let* ((name (downcase (match-string 1 match))) - (sym (intern name))) + (sym (intern-soft name))) (if (memq sym yas--exported-syms) (format "[[#%s][=%s=]]" name name) (format "=%s=" name)))) - body t)) + body t t) + body (replace-regexp-in-string + "\n\n +(.+\\(?:\n +.+\\)*" + (lambda (match) + (concat "\n#+BEGIN_SRC elisp\n" + match + "\n#+END_SRC\n")) + body t t)) ;; output the paragraph (concat heading after-heading "\n" body))) diff --git a/yasnippet.el b/yasnippet.el index 11bc270..6a27812 100644 --- a/yasnippet.el +++ b/yasnippet.el @@ -237,7 +237,7 @@ nil. - To signal that the user quit the prompting process, you can signal `quit' with - (signal \\='quit \"user quit!\")." + (signal \\='quit \"user quit!\")" :type '(repeat function)) (defcustom yas-indent-line 'auto From d364425176a707c43db176ab79433e149a435d37 Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Sun, 18 Feb 2018 07:46:06 -0500 Subject: [PATCH 4/4] * yasnippet.el (yas-field-value): Fix docstring. --- yasnippet.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/yasnippet.el b/yasnippet.el index 6a27812..0d41241 100644 --- a/yasnippet.el +++ b/yasnippet.el @@ -2946,7 +2946,8 @@ Otherwise signal `yas-exception'." (defun yas-field-value (number) "Get the string for field with NUMBER. -Use this in primary and mirror transformations to tget." +Use this in primary and mirror transformations to get the text of +other fields." (let* ((snippet (car (yas-active-snippets))) (field (and snippet (yas--snippet-find-field snippet number))))