Looking for new maintainer for ob-sql-mode

2022-12-01 Thread Nik Clayton
Hi,

I wrote https://github.com/nikclayton/ob-sql-mode as a thing that scratched
my own itch a few years ago. Since then my need for it has disappeared, but
kind people occasionally report issues or send PRs.

I'm not really in a position to review them, so I'm looking for someone who
would be interested in taking over maintainership.

N
ᐧ


[O] Case sensitivity of special block names in HTML export / class names

2019-07-29 Thread Nik Clayton
Hoi,

Org special block names (within Org) appear to be case-insensitive. That
is, I can write either:

#+BEGIN_NOTES
...
#+END_NOTES

or

#+begin_notes
...
#+end_notes

and Org is happy. I think the switch from Org 8 to 9 changed the default
templates to insert lower-case blocks instead of upper case blocks, so it's
natural now to have files that contain a mix of both cases.

This is a problem for HTML export, as they get converted to:

...

or

...

depending on the original case of the special block in the .org file. HTML
class element values are case sensitive in non-quirks mode browsers, so
this makes existing CSS for content exported by Org fail, as

div.NOTES { ... }

does not match a .

A quick local fix is:

(defun my/downcase-special-block (ohsb special-block contents info)
  (let ((special-block-copy (org-element-copy special-block)))
(org-element-put-property
 special-block-copy
 :type
 (downcase (org-element-property :type special-block)))
(funcall ohsb special-block-copy contents info)))

(advice-add #'org-html-special-block :around
#'my/downcase-special-block)

But I wanted to raise this in case there was any interest in a more general
solution (perhaps a configuration option to either (a) retain case (current
behaviour), (b) convert to lower case, (c) convert to upper case?

N


[O] PATCHES: Wrap code in , add an attribute for line number value

2019-06-04 Thread Nik Clayton
Hi,

Attached are two TINYCHANGE patches that provide an alternative way of
displaying line numbers in generated HTML output.

The current approach hardcodes a span containing preformated text. It's
non-trivial to move this in the displayed output or adjust the formatting.
The content is also part of the selectable part of the page, so if you
copy/paste code from an ORG -> HTML file you get the line numbers as well.

The first patch just wraps each line of code in a  element. The
second patch extends this to include the line number of that element as a
special data- attribute. The value of this can be accessed in CSS to
display the line number, format it in interesting ways, etc, while keeping
it non-selectable, so that copy/pasting the code ignores the line numbers.

N


0001-ox-html.el-Wrap-each-line-of-a-source-block-in-a-cod.patch
Description: Binary data


0002-ox-html.el-Include-the-line-number-as-a-data-attribu.patch
Description: Binary data


[O] API for manipulating #+PROPERTY entries?

2019-03-04 Thread Nik Clayton
Hoi,

Is there an API for manipulating properties that are set in #+PROPERTY
lines before the first headline of a file (i.e., not in a property drawer)?

I've got some properties that (a) make sense when set for the whole file,
and (b) the file contains multiple first level headings (which isn't going
to change).

Using org-entry-put when point is before the first headline throws a
"Before first headline" error (when when the #+PROPERTY line already exists
and I want to update an existing entry).

N


[O] Org-Babel: Alternate caching behaviour when file does not exist

2019-01-23 Thread Nik Clayton
I discovered that if you have ":cache yes" set on a SRC block, with the
results being written to a file with ":results filename.png", Org Babel
will not re-evaluate the block if the file doesn't exist and the cache
checksum hasn't changed.

This caused me a problem, as the .org files that I'm sharing with
colleagues in a VCS have the cache option enabled -- I'd assumed that the
first time they tried to export the file the images would be generated and
then not regenerated on subsequent exports. That turned out to be wrong,
and I can see why Org Babel has decided to go that way.

In case anyone else stumbles on to this and finds this in the archives,
here's some advice around the org-babel-current-result-hash that checks to
see if the linked file exists, and ignores the cache if it doesn't.

Hope that's helpful to someone -- N


(require 'f)
(defun my/org-babel-current-result-hash ()
  "Alter org-babel caching behaviour.

If you have `:cache yes' set the cached result is used even if
the file doesn't exist.  Fix this by advising the function that
computes the hash of the current content, and check to see if
the file is present."
  (save-excursion
;; Find the results block, and go to the first non-whitespace
;; content on the following line.
(goto-char (org-babel-where-is-src-block-result))
(forward-line)
(skip-chars-forward " ")
;; If the context is a link to a local file check to see if the
;; file exists. If it does proceed to org-babel-current-result-hash
;; as normal, if it doesn't return nil, and force the file to be
;; generated.
(let ((ctx (org-element-context)))
  (if (and ctx (listp ctx) (eq 'link (car ctx)) (string= "file"
(org-element-property :type ctx)))
  (f-exists? (f-join (f-dirname buffer-file-name) (org-element-property
:path ctx)))
t

(advice-add #'org-babel-current-result-hash
:before-while
#'my/org-babel-current-result-hash)


[O] company-mode completions for noweb references

2018-11-06 Thread Nik Clayton
Hoi,

I've been writing a few things using Org where I'm making frequent use of
noweb references in SRC blocks, and decided that completion would be handy
for them.

This function will complete "^<<" with a list of the defined named blocks
in the current file, if you're in a SRC block.

It could be made smarter (e.g., only offer the completion if ":noweb yes"
is set, only offer to complete from named blocks with the same language as
the current block), but I thought I'd throw it out here in case anyone else
finds it useful.

Best, N

(defun my/org-src-block-name-backend (command  arg  ignored)
  "Complete `<<' with the names of defined SRC blocks."
  (interactive (list 'interactive))
  (cl-case command
(interactive (company-begin-backend 'my/org-src-block-name-backend))
(init (require 'org-element))
(prefix (and (eq major-mode 'org-mode)
 (eq 'src-block (car (org-element-at-point)))
 (cons (company-grab-line "^<<\\(\\w*\\)" 1) t)))
(candidates
 (org-element-map (org-element-parse-buffer) 'src-block
   (lambda (src-block)
 (let ((name (org-element-property :name src-block)))
   (when name
 (propertize
  name
  :value (org-element-property :value src-block)
  :annotation (org-element-property :raw-value (org-element-lineage
src-block '(headline)
(sorted t); Show candidates in same order as doc
(ignore-case t)
(duplicates nil)   ; No need to remove duplicates
(post-completion   ; Close the reference with ">>"
 (insert ">>"))
;; Show the contents of the block in a doc-buffer. If you have
;; company-quickhelp-mode enabled it will show in a popup
(doc-buffer (company-doc-buffer (get-text-property 0 :value arg)))
(annotation (format " [%s]" (get-text-property 0 :annotation arg)

(add-to-list 'company-backends 'my/org-src-block-name-backend)


[O] Best way to process a collection of .org files as one?

2018-11-01 Thread Nik Clayton
Hoi,

What's the best way to process (ideally using the org-element API) a
collection of .org files as one larger file?

I'm using Org + ox-reveal to write the course material for a three month
course. This is a lot of material, so keeping it in one Org file is not
practical (exporting it to the slides takes longer, it's easier to have
multiple buffers open and switch between them, etc).

To help ensure that I'm covering the content in a sensible order I've given
each heading optional TOPIC and REQUIREMENTS properties. When a new topic
is introduced I add an identifier to the TOPIC property to the heading that
introduces it, and if a heading requires that a topic or topics have been
introduced I add the topic identifiers as a space-separated string to the
REQUIREMENTS property.

I have a small function that uses the org-element API to iterate over all
the headings in a file and tell if if I have any headings that list a
requirement without that requirement appearing in a TOPIC property earlier
in the file.

This works when the file is self contained.

When I have topics that might be introduced in one file, and later
referenced in a second file, it obviously doesn't.

I thought one approach would be to have a master Org file that references
all the others, so course.org that looks like:

#+INCLUDE "day1.org"
#+INCLUDE "day2.org"
#+INCLUDE "day3.org"
...

However, org-element-parse-buffer doesn't recurse in to the included files,
so this doesn't work.

I could write my own function to create the recursive expansion of all the
content, but before I do that I thought I'd check to see if there's a
better way of doing what I'm trying to achieve.

Any ideas?

N


[O] (no subject)

2018-10-15 Thread Nik Clayton
Hi,

I'd like to propose a couple of changes / enhancements to how org-export
exports some data in to HTML files to make it slightly easier to style
those files.

The first is re line-numbers.

At the moment those get exported as content in the HTML, although they're
really additional metadata. Amongst other things, this means that if you
copy/paste from the output you get the line numbers included in the text
that's copied.

CSS supports arbitrary counters that can be associated with content,
starting from an arbitrary value. My current hack that sort of works is the
following CSS:

/* Hide the current line numbers */
span.linenr {
  display: none;
}

/* Style each line. Maintain a counter for each line, increment
   by one for each ... element.
.reveal pre.src code {
  display: inline;
  font-size: 125%;
  line-height: 1.2;
  counter-increment: line;
}

/* Show a line number before each line. */
.reveal pre.src code:before {
  content: counter(line);
  border-right: 1px solid #ddd;
  padding: 0 0.5em;
  margin-right: 0.5em;
  width: 1em;
  display: inline-block;
  text-align: right;
}

and a change to org-html-do-format-code to wrap each line in its own
... element:

...
  ;; Transcoded src line.
  (format "%s" loc)
...

But this adds line numbers to all code blocks, irrespective of the "-n"
option, and they all start from one.

What I'd like to do is change the output to:

1. Omit the ..." content.
2. Add an additional class to the pre element to indicate whether or not
this block should have line numbers.
3. Add a data-ox-starting-number (or similar) attribute to the pre element
that specifies what the starting line number for this block should be.

Couple of questions before I write a patch:

a) Does that sound reasonable?
b) Should this replace the current approach, or be an option that can be
toggled by a customisation?


And the second is re languages associated with exported SRC blocks.

At the moment the language is mentioned as src-... class (src-html,
src-javascript, etc).

I'd like to put the language in a data-ox-src-language attribute as well
(e.g., ...) so
that I can put use CSS to put badges indicating the language in the output.

Per
https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes
that would look something like:

.src:after {
  content: attr(data-ox-src-language);
  position: absolute;
  top: -10px;
  right: -10px;
  font-size: 70%;
  background: green;
  color: white;
  text-align: center;
  line-height: 18px;
  border-radius: .25em;
  padding: 0 0.5em;
  box-shadow: 0 0 1px #333;
}

I see there's already some code that tries to show language badges on hover
(which doesn't work for me for some reason, I haven't dug in to why).

Does this change sound reasonable?

Here's a screenshot from an export showing early versions of these changes
in action. Notice how the selected text (the first function) doesn't
include the line numbers in the selection.

[image: image.png]

N


[O] RFC: ob-sql-mode.el: Use sql-mode with Org Babel

2016-12-17 Thread Nik Clayton
Hoi,

I'd like to solicit feedback on ob-sql-mode.el,
https://github.com/nikclayton/org-mode/commit/106b22e9ef4835e15efc47d63aaeee675a1ebb69
.

This introduces a new Org Babel language, "sql-mode". Unlike the current
"sql" language, this one uses sql-mode to manage the interaction with the
SQL interpreters, so it supports all the backends that sql-mode supports.

It also supports sessions, so you can have different src blocks connected
to different databases or configurations in that database.

If you have, for example, "sqlite" installed on your system, you can put
the following (rather trivial) query in an Org file and evaluate it in the
usual way

#+BEGIN_SRC sql-mode :product sqlite
SELECT 1, 2, 3;
#+END_SRC

The evaluation result will look like

#+RESULTS:
: 1|2|3


Org property headers and drawers are also supported, so you could omit the
:product argument if you had

#+PROPERTY: header-args:sql-mode :product sqlite

or a property drawer that looked like

:PROPERTIES:
:header-args: :product sqlite
:END:

in scope.

​I'm about to go on vacation for a few weeks, so won't have the chance to
respond to feedback until early January, but I wanted to get this out
there. I'm releasing this in my capacity as a Google employee, and Google
has a copyright assignment on file with the FSF.​

Best, ​N
-- 
Google Switzerland GmbH, Identifikationsnummer: CH-020.4.028.116-1


[O] RFC: ob-sql-mode.el: Use sql-mode with Org Babel

2016-12-17 Thread Nik Clayton
Hoi,

I'd like to solicit feedback on ob-sql-mode.el, https://github
.com/nikclayton/org-mode/commit/106b22e9ef4835e15efc47d63aaeee675a1ebb69.

This introduces a new Org Babel language, "sql-mode". Unlike the current
"sql" language, this one uses sql-mode to manage the interaction with the
SQL interpreters, so it supports all the backends that sql-mode supports.

It also supports sessions, so you can have different src blocks connected
to different databases or configurations in that database.

If you have, for example, "sqlite" installed on your system, you can put
the following (rather trivial) query in an Org file and evaluate it in the
usual way

#+BEGIN_SRC sql-mode :product sqlite
SELECT 1, 2, 3;
#+END_SRC

The evaluation result will look like

#+RESULTS:
: 1|2|3


Org property headers and drawers are also supported, so you could omit the
:product argument if you had

#+PROPERTY: header-args:sql-mode :product sqlite

or a property drawer that looked like

:PROPERTIES:
:header-args: :product sqlite
:END:

in scope.

​I'm about to go on vacation for a few weeks, so won't have the chance to
respond to feedback in detail until early January, but I wanted to get this
out there. I'm releasing this in my capacity as a Google employee, and
Google has a copyright assignment on file with the FSF.​

Best, ​N
-- 
Google Switzerland GmbH, Identifikationsnummer: CH-020.4.028.116-1


Re: [O] Bug: Property inheritance not working in columns [7.9.3f (release_7.9.3f-17-g7524ef @ /usr/share/emacs/24.3/lisp/org/)]

2015-06-03 Thread Nik Clayton
On 2 June 2015 at 21:02, Nicolas Goaziou m...@nicolasgoaziou.fr wrote:

 Nik Clayton n...@ngo.org.uk writes:

  I also see the same problem in agenda view (org-agenda-columns)

 Fixed in 03936a50f4fe9a261577d467098ed1080c61cb6e. Thank you.


Great. Thanks again -- N

-- 
http://try-dot-ch.blogspot.com/


[O] Bug: Property inheritance not working in columns [7.9.3f (release_7.9.3f-17-g7524ef @ /usr/share/emacs/24.3/lisp/org/)]

2015-06-02 Thread Nik Clayton
Property inheritance does not seem to work when running C-c C-x C-c
(org-columns).

Reproduction recipe:

1. Start emacs with emacs -Q

2. Evaluate the following to enable property inheritance, and to define
custom columns that include the value of the PROJECT property.

  (setq org-columns-default-format
%CATEGORY %15PROJECT(Project) %55ITEM(Task))

  (setq org-use-property-inheritance t)

3. Load the following in to an org-mode buffer.

* TODO Test
  :PROPERTIES:
  :CATEGORY: Cat. Name
  :PROJECT: Proj. Name
  :END:

** TODO A subtask
   This is a subtask

** TODO Another subtask
   This is another subtask


4. Run C-c C-x C-c in the buffer to enable org-columns.


Expected result:

A buffer that looks something like:

CATEGORY  | Project  | Task
Cat. Name | Proj. Name   | * TODO Test
Cat. Name | Proj. Name   | ** TODO A subtask
Cat. Name | Proj. Name   | ** TODO Another subtask


Actual result:

A buffer where the PROJECT property has not been inherited, and looks
like this:

CATEGORY  | Project  | Task
Cat. Name | Proj. Name   | * TODO Test
Cat. Name |  | ** TODO A subtask
Cat. Name |  | ** TODO Another subtask


Inspecting the value of the variable org-columns-default-format with
M-x show-variable tells me:

org-columns-default-format's value is
%CATEGORY %15PROJECT(Project) %55ITEM(Task)
Original value was
%25ITEM %TODO %3PRIORITY %TAGS


I can also reproduce this on org-mode from the Git repository
(reproduced with 1a7364177046...) and it's also noted on
http://emacs.stackexchange.com/questions/7335.


Emacs  : GNU Emacs 24.3.1 (x86_64-pc-linux-gnu, GTK+ Version 3.10.7)
 of 2014-03-07 on lamiak, modified by Debian
Package: Org-mode version 7.9.3f (release_7.9.3f-17-g7524ef @
/usr/share/emacs/24.3/lisp/org/)

current state:
==
(setq
 org-export-preprocess-before-selecting-backend-code-hook
'(org-beamer-select-beamer-code)
 org-tab-first-hook '(org-hide-block-toggle-maybe
  org-src-native-tab-command-maybe
  org-babel-hide-result-toggle-maybe
  org-babel-header-arg-expand)
 org-speed-command-hook '(org-speed-command-default-hook
  org-babel-speed-command-hook)
 org-occur-hook '(org-first-headline-recenter)
 org-metaup-hook '(org-babel-load-in-session-maybe)
 org-export-preprocess-before-normalizing-links-hook
'(org-remove-file-link-modifiers)
 org-confirm-shell-link-function 'yes-or-no-p
 org-columns-default-format %CATEGORY %15Project(Project) %55ITEM(Task)
 org-export-latex-final-hook '(org-beamer-amend-header org-beamer-fix-toc
   org-beamer-auto-fragile-frames
   org-beamer-place-default-actions-for-lists)
 org-export-latex-after-initial-vars-hook '(org-beamer-after-initial-vars)
 org-after-todo-state-change-hook '(org-clock-out-if-current)
 org-src-mode-hook '(org-src-babel-configure-edit-buffer
 org-src-mode-configure-edit-buffer)
 org-agenda-before-write-hook '(org-agenda-add-entry-text)
 org-babel-pre-tangle-hook '(save-buffer)
 org-mode-hook '(#[nil \300\301\302\303\304$\207
   [org-add-hook change-major-mode-hook org-show-block-all
append local]
   5]
 #[nil \300\301\302\303\304$\207
   [org-add-hook change-major-mode-hook
org-babel-show-result-all append local]
   5]
 org-babel-result-hide-spec org-babel-hide-all-hashes)
 org-ctrl-c-ctrl-c-hook '(org-babel-hash-at-point
  org-babel-execute-safely-maybe)
 org-cycle-hook '(org-cycle-hide-archived-subtrees org-cycle-hide-drawers
  org-cycle-show-empty-lines
  org-optimize-window-after-visibility-change)
 org-export-latex-format-toc-function 'org-export-latex-format-toc-default
 org-export-blocks '((src org-babel-exp-src-block nil)
 (export-comment org-export-blocks-format-comment t)
 (ditaa org-export-blocks-format-ditaa nil)
 (dot org-export-blocks-format-dot nil))
 org-export-first-hook '(org-beamer-initialize-open-trackers)
 org-export-interblocks '((src org-babel-exp-non-block-elements))
 org-use-property-inheritance t
 org-confirm-elisp-link-function 'yes-or-no-p
 org-metadown-hook '(org-babel-pop-to-session-maybe)
 org-clock-out-hook '(org-clock-remove-empty-clock-drawer)
 )


-- 
http://try-dot-ch.blogspot.com/


[O] Bug: Property inheritance not working in columns [7.9.3f (release_7.9.3f-17-g7524ef @ /usr/share/emacs/24.3/lisp/org/)]

2015-06-02 Thread Nik Clayton
Property inheritance does not seem to work when running C-c C-x C-c
(org-columns).

Reproduction recipe (I can also reproduce this on org-mode from the Git
repository
(reproduced with 1a7364177046... and it's also noted on
http://emacs.stackexchange.com/questions/7335).


1. Start emacs with emacs -Q

2. Evaluate the following to enable property inheritance, and to define
custom columns that include the value of the PROJECT property.

  (setq org-columns-default-format
%CATEGORY %15PROJECT(Project) %55ITEM(Task))

  (setq org-use-property-inheritance t)

3. Load the following in to an org-mode buffer.

* TODO Test
  :PROPERTIES:
  :CATEGORY: Cat. Name
  :PROJECT: Proj. Name
  :END:

** TODO A subtask
   This is a subtask

** TODO Another subtask
   This is another subtask


4. Run C-c C-x C-c in the buffer to enable org-columns.


Expected result:

A buffer that looks something like:

CATEGORY  | Project  | Task
Cat. Name | Proj. Name   | * TODO Test
Cat. Name | Proj. Name   | ** TODO A subtask
Cat. Name | Proj. Name   | ** TODO Another subtask


Actual result:

A buffer where the PROJECT property has not been inherited, and looks
like this:

CATEGORY  | Project  | Task
Cat. Name | Proj. Name   | * TODO Test
Cat. Name |  | ** TODO A subtask
Cat. Name |  | ** TODO Another subtask


Inspecting the value of the variable org-columns-default-format with
M-x show-variable tells me:

org-columns-default-format's value is
%CATEGORY %15PROJECT(Project) %55ITEM(Task)
Original value was
%25ITEM %TODO %3PRIORITY %TAGS




Emacs  : GNU Emacs 24.3.1 (x86_64-pc-linux-gnu, GTK+ Version 3.10.7)
 of 2014-03-07 on lamiak, modified by Debian
Package: Org-mode version 7.9.3f (release_7.9.3f-17-g7524ef @
/usr/share/emacs/24.3/lisp/org/)

current state:
==
(setq
 org-export-preprocess-before-selecting-backend-code-hook
'(org-beamer-select-beamer-code)
 org-tab-first-hook '(org-hide-block-toggle-maybe
  org-src-native-tab-command-maybe
  org-babel-hide-result-toggle-maybe
  org-babel-header-arg-expand)
 org-speed-command-hook '(org-speed-command-default-hook
  org-babel-speed-command-hook)
 org-occur-hook '(org-first-headline-recenter)
 org-metaup-hook '(org-babel-load-in-session-maybe)
 org-export-preprocess-before-normalizing-links-hook
'(org-remove-file-link-modifiers)
 org-confirm-shell-link-function 'yes-or-no-p
 org-columns-default-format %CATEGORY %15Project(Project) %55ITEM(Task)
 org-export-latex-final-hook '(org-beamer-amend-header org-beamer-fix-toc
   org-beamer-auto-fragile-frames
   org-beamer-place-default-actions-for-lists)
 org-export-latex-after-initial-vars-hook '(org-beamer-after-initial-vars)
 org-after-todo-state-change-hook '(org-clock-out-if-current)
 org-src-mode-hook '(org-src-babel-configure-edit-buffer
 org-src-mode-configure-edit-buffer)
 org-agenda-before-write-hook '(org-agenda-add-entry-text)
 org-babel-pre-tangle-hook '(save-buffer)
 org-mode-hook '(#[nil \300\301\302\303\304$\207
   [org-add-hook change-major-mode-hook org-show-block-all
append local]
   5]
 #[nil \300\301\302\303\304$\207
   [org-add-hook change-major-mode-hook
org-babel-show-result-all append local]
   5]
 org-babel-result-hide-spec org-babel-hide-all-hashes)
 org-ctrl-c-ctrl-c-hook '(org-babel-hash-at-point
  org-babel-execute-safely-maybe)
 org-cycle-hook '(org-cycle-hide-archived-subtrees org-cycle-hide-drawers
  org-cycle-show-empty-lines
  org-optimize-window-after-visibility-change)
 org-export-latex-format-toc-function 'org-export-latex-format-toc-default
 org-export-blocks '((src org-babel-exp-src-block nil)
 (export-comment org-export-blocks-format-comment t)
 (ditaa org-export-blocks-format-ditaa nil)
 (dot org-export-blocks-format-dot nil))
 org-export-first-hook '(org-beamer-initialize-open-trackers)
 org-export-interblocks '((src org-babel-exp-non-block-elements))
 org-use-property-inheritance t
 org-confirm-elisp-link-function 'yes-or-no-p
 org-metadown-hook '(org-babel-pop-to-session-maybe)
 org-clock-out-hook '(org-clock-remove-empty-clock-drawer)
 )


Re: [O] Bug: Property inheritance not working in columns [7.9.3f (release_7.9.3f-17-g7524ef @ /usr/share/emacs/24.3/lisp/org/)]

2015-06-02 Thread Nik Clayton
Hi Nicolas,

On 2 June 2015 at 16:06, Nicolas Goaziou m...@nicolasgoaziou.fr wrote:

 Fixed in 0f93638ce1b29792033231426a4555e538f5c959. Thank you.


That was quick, thanks.

I also see the same problem in agenda view (org-agenda-columns)

N
-- 
http://try-dot-ch.blogspot.com/