Commit Graph

21 Commits

Author SHA1 Message Date
Ihor Radchenko a2e5685e49
Do not use org-fold to hide link parts
* lisp/ol.el (org-link--link-folding-spec):
(org-link--description-folding-spec):
(org-link-descriptive-ensure): Remove.
(org-toggle-link-display): Rely upon font-lock to update link display.
* lisp/org-agenda.el (org-agenda-mode): Remove no-longer-necessary
org-fold initializer.
* lisp/org-fold.el (org-fold-initialize): Remove link-related fold
types.
(org-fold-show-set-visibility):
* lisp/org-src.el (org-src-font-lock-fontify-block):
* lisp/org.el (org-do-emphasis-faces):
(org-unfontify-region): Remove special handling of link folds.
* lisp/org.el (org-mode): Remove folding setup for links.
(org-activate-links--text-properties): Remove.
(org-activate-links): Honor `org-link-descriptive' dynamically.

This change reflects de-facto situation where we cannot use folding
system to hide links reliably.  Even though we promise in Org 9.6 that
hidden parts of the link can be searched, the way it can be
implemented is not reliable and is working around upstream mechanisms.
Upstream changes are necessary to properly support isearch in text
hidden using text properties; workarounds attempted in org-fold-core
do not cut it because too many built-in Emacs libraries and also
third-party libraries rely upon internal implementation details of
isearch (due to limitations of its API).
2024-05-02 12:29:27 +03:00
Rick Lupton 95554543b9
org-id.el: Add search strings, inherit parent IDs
* lisp/ol.el (org-store-link): Refactor org-id links to use standard
`org-store-link-functions'.
(org-link-search): Create new headings at appropriate level.
(org-link-precise-link-target): New function extracting logic to
identify a precise link target, e.g. a heading, named object, or text
search.
(org-link-try-link-store-functions): Extract logic to call external
link store functions. Pass them a new `interactive?' argument.
* lisp/ol-bbdb.el (org-bbdb-store-link):
* lisp/ol-bibtex.el (org-bibtex-store-link):
* lisp/ol-docview.el (org-docview-store-link):
* lisp/ol-eshell.el (org-eshell-store-link):
* lisp/ol-eww.el (org-eww-store-link):
* lisp/ol-gnus.el (org-gnus-store-link):
* lisp/ol-info.el (org-info-store-link):
* lisp/ol-irc.el (org-irc-store-link):
* lisp/ol-man.el (org-man-store-link):
* lisp/ol-mhe.el (org-mhe-store-link):
* lisp/ol-rmail.el (org-rmail-store-link): Accept optional arg.
* lisp/org-id.el (org-id-link-consider-parent-id): New option to allow
a parent heading with an id to be considered as a link target.
(org-id-link-use-context): New option to add context to org-id links.
(org-id-get): Add optional `inherit' argument which considers parents'
IDs if the current entry does not have one.
(org-id-store-link): Consider IDs of parent headings as link targets
when current heading has no ID and `org-id-link-consider-parent-id' is
set.  Add a search string to the link when enabled.
(org-id-store-link-maybe): Function set as :store option for custom id
link property. Move logic from `org-store-link' here to determine when
an org-id link should be stored using `org-id-store-link'.
(org-id-open): Recognise search strings after "::" in org-id links.
* lisp/org-lint.el: Add checker for "::" in ID properties.
* testing/lisp/test-ol.el: Add tests for
`org-link-precise-link-target' and `org-id-store-link' functions,
testing new options.
* doc/org-manual.org: Update documentation about links.
* etc/ORG-NEWS: Document changes and new options.

These feature allows for more precise links when using org-id to link to
org headings, without requiring every single headline to have an id.

Link: https://list.orgmode.org/118435e8-0b20-46fd-af6a-88de8e19fac6@app.fastmail.com/
2024-02-24 15:56:44 +03:00
Ihor Radchenko 173b5de0ec
testing: Re-introduce more useful new tests instead of deleted dupllicates
* testing/lisp/test-ol.el (test-org-link/store-link):
* testing/lisp/test-org-table.el (test-org-table/get-field):
* testing/lisp/test-org.el (test-org/auto-fill-function): Add modified
version of the removed test duplicates, according to their likely
original intention.

Link: https://orgmode.org/list/87cz0wyw9m.fsf@localhost
2023-08-08 15:40:59 +03:00
Ilya Chernyshov fe85d61a92
testing: Delete duplicate tests
* testing/lisp/test-ol.el (test-org-link/store-link): Delete a duplicate test.

* testing/lisp/test-org-clock.el (test-org-clock/clocktable/properties): Delete a duplicate test.

* testing/lisp/test-org-element.el (test-org-element/link-parser,
test-org-element/timestamp-parser): Delete duplicate tests.

* testing/lisp/test-org-table.el (test-org-table/get-field): Delete a duplicate test.

* testing/lisp/test-org.el (test-org/auto-fill-function): Delete a duplicate test.
2023-08-08 15:33:06 +03:00
Ihor Radchenko 6074a22bcb
testing: Address FIXMEs identified in 1a5e3f931
* testing/lisp/test-ob.el (test-ob/blocks-with-spaces):
(test-ob/specific-colnames):
* testing/lisp/test-oc.el (test-org-cite/export-capability):
* testing/lisp/test-ol.el (test-org-link/store-link):
* testing/lisp/test-org.el (test-org/set-regexps-and-options):
* testing/org-test.el (org-test-base-dir): Address typos and
non-existent variables.

(missing-test-dependency): Use `define-error'.
(org-test-load): Set `org-id-locations-file' when running tests.

* testing/lisp/test-ox.el (test-org-export/bind-keyword): Clarify
about variable symbol defined inside setupfile #+BIND statemtn.
2022-09-16 11:30:16 +08:00
Stefan Monnier 1a5e3f931c
testing: Make all files use `lexical-binding`
Mainly, add the corresponding cookie, but also add various `require`s
so that the compiler knows which vars should be trated as dynbound.
This does not fix all the warnings, but does try to eliminate
all those about "unused" variables.  For the variables truly unused,
the patch usually adds an underscore to their name to silence the warning.

Some of the fixes affect files which already used `lexical-binding`.
Not sure why the test worked before: maybe because the tests were run
without compiling them first (which could cause some of the
missing `require`d packages to be autoloaded before we got to the
problematic code, thus hiding the problem)?

I found some suspicious code, for which I added FIXMEs.

There are also a few changes to the main files.

* lisp/org-protocol.el (org-protocol-check-filename-for-protocol):
Don't call `server-edit` if it's not yet defined.  [ Needed to get
the tests to pass. ]

* lisp/ob-core.el (org-babel-temporary-directory)
(org-babel-temporary-stable-directory): Always define (and use nil
if we don't want to create a directory for it).  Simplify the code based
on the fact that (defvar V E) only evaluates E if V is not yet `boundp`.
(org-babel-temp-file, org-babel-temp-stable-file)
(org-babel-remove-temporary-directory)
(org-babel-remove-temporary-stable-directory): Adjust accordingly.

* lisp/org.el (org-log-beginning): Add FIXME.

* testing/org-test.el: Require `org` and `org-id`.
(org-id-locations-file): Don't `defconst` it.
(org-test-at-id, org-test-in-example-file, org-test-at-marker)
(org-test-with-temp-text, org-test-with-temp-text-in-file): Move edebug
specs into `declare` (and simplify them).
(org-test-with-tramp-remote-dir--worker): Declare dynbound tramp vars.
(org--compile-when): Fix quoting of `exp`.
(org-test-load): Tweak regexps.

* testing/org-batch-test-init.el: Tweak regexp, remove dead code and
add a FIXME about it.

* testing/lisp/test-ox.el: Require `ox` instead of
erroring out if it's not already loaded.  Also require `org-inlinetask`.
(org-test-with-parsed-data): Silence warnings when `info` is not used.
(test-org-export/bind-keyword): Add FIXME.

* testing/lisp/test-ox-publish.el: Require `org-test` and `ox-publish`.
(test-org-publish/resolve-external-link): Expose lambdas to
the compiler.  Remove unused var `ids`.
(test-org-publish/get-project-from-filename): Remove unused var `file`.

* testing/lisp/test-org.el: Require `org-macs`, `org`,
`org-inlinetask`, `org-refile`, and `org-agenda`.
(test-org/org-read-date): Declare `org-time-was-given` as dynbound.
(test-org/set-regexps-and-options): Add FIXME.

* testing/lisp/test-org-timer.el: Require `org-timer`.

* testing/lisp/test-org-table.el: Require `ox`.

* testing/lisp/test-org-protocol.el: Require `org-protocol` instead of
erroring out if it's not already loaded.  Also require `capture`, and
add missing `provide` statement.

* testing/lisp/test-org-pcomplete.el: Require `org`.

* testing/lisp/test-org-list.el: Require `org-list` and `org`.

* testing/lisp/test-org-lint.el: Require `org-footnote` and `org-lint`.

* testing/lisp/test-org-footnote.el: Require `org-footnote`.

* testing/lisp/test-org-element.el: Require `org-element` instead of
erroring out if it's not already loaded.  Also require `org` and
`org-inlinetask`.

* testing/lisp/test-org-duration.el: Require `org-duration`.

* testing/lisp/test-org-datetree.el: Require `org-datetree`.

* testing/lisp/test-org-colview.el: Require `org-colview`,
`org-duration`, and `org-inlinetask`.

* testing/lisp/test-org-clock.el: Require `org-duration` and `org-clock`.

* testing/lisp/test-org-archive.el: Require `org-archive`.

* testing/lisp/test-org-agenda.el
(test-org-agenda/bulk-custom-arg-func): Add FIXME.

* testing/lisp/test-ol.el: Require `ol` and `org-id`.
(test-org-link/store-link): Declare `org-store-link-props` and add FIXME.

* testing/lisp/test-oc.el (test-org-cite/export-capability): Add FIXME.

* testing/lisp/test-ob.el: Require `ob-core`, `org-src`, `ob-ref`,
and `org-table`.
(test-ob/eval-header-argument): Rename `foo` to `test-ob--foo` and
declare it as dynbound.
(test-ob/blocks-with-spaces, test-ob/specific-colnames): Add FIXME.
(test-ob/noweb-expansions-in-cache):
Declare `noweb-expansions-in-cache-var` as dynbound.

* testing/lisp/test-ob-tangle.el: Require `org` and `ob-tangle`.

* testing/lisp/test-ob-shell.el:
* testing/lisp/test-ob-python.el: Require `ob-core`.

* testing/lisp/test-ob-lob.el: Require `ob-lob`.
(temporary-value-for-test): Declare as dynbound.

* testing/lisp/test-ob-plantuml.el: Require `ob-plantuml` instead of
erroring out if it's not already loaded.
* testing/lisp/test-ob-lilypond.el: Require `ob-lilypond` instead of
erroring out if it's not already loaded.  Use `with-current-buffer`.

* testing/lisp/test-ob-julia.el: Require `ob-core`.

* testing/lisp/test-ob-java.el (org-babel-temporary-directory):
Remove dead code now that `org-babel-temporary-directory` is always bound.

* testing/lisp/test-ob-exp.el: Require `ob-exp`, `org-src`, and `org-test`.
(ob-exp/evaluate-all-executables-in-order):
Declare `*evaluation-collector*` as dynbound.

* testing/lisp/test-ob-emacs-lisp.el (ob-emacs-lisp/dynamic-lexical-edit)
(ob-emacs-lisp/dynamic-lexical-execute):
Rename dynbound var to `ob-emacs--x` and declare it as such.

* testing/lisp/test-ob-R.el: Require `ob-core`.
(ess-ask-for-ess-directory, ess-history-file): Declare vars.
2022-09-15 19:17:19 +08:00
Ihor Radchenko 86c4635dba
test-org-link/store-link: Update tests for 4fc2c8dd8
* testing/lisp/test-ol.el (test-org-link/store-link): Do not expect
duplicating raw link in the file link description.
2022-09-13 22:11:05 +08:00
Ihor Radchenko f71546cc9f
* testing/lisp/test-ol.el: Fix test name
(test-org-link/insert-link-insert-description): Use test name matching
test regexp selector.
2022-08-06 13:52:44 +08:00
Hugo Heagren 2bbb92a72d
test-ol: tests for insert-description param when inserting links
* test-ol (test-ol-with-link-parameters-as): Convenience macro for
testing.
(test-ol-insert-link-get-desc): Convenience macro for testing.
(test-ol/return-foobar): Convenience function for testing.
(test-ol/insert-link-insert-description): Test for various values of
`:insert-description' in `org-link-parameters' (including
`test-ol/return-foobar').
2022-08-06 13:46:36 +08:00
Max Nikulin 20274454c6
test-ol: Rename cases to match the default selector
* testing/lisp/test-ol.el (test-ol/encode): Rename to
`test-org-link/encode'.
(test-ol/decode): Rename to `test-org-link/decode'.
(test-ol/encode-url-with-escaped-char): Rename to
`test-org-link/encode-url-with-escaped-char'.
(test-ol/org-toggle-link-display): Rename to
`test-org-link/toggle-link-display'.
(test-ol/escape): Rename to `test-org-link/escape'.
(test-ol/unescape): Rename to `test-org-link/unescape'.
(test-ol/make-string): Rename to `test-org-link/make-string'.
(test-ol/store-link): Rename to `test-org-link/store-link'.
(test-ol/update-radio-target-regexp): Rename to
`test-org-link/update-radio-target-regexp'.
(test-ol/next-link): Rename to `test-org-link/next-link'.
(test-ol/previous-link): Rename to `test-org-link/previous-link'.
(test-ol/plain-link-re): Rename to `test-org-link/plain-link-re'.

Only `test-ol/org-toggle-link-display' was executed during
"make test" since it is the only name matched by the "org|ob" default
selector.  Reported in: Ihor Radchenko to emacs-orgmode.
Re [PATCH v7] ol.el: add description format parameter
to org-link-parameters.  Sun, 24 Jul 2022 21:15:31 +0800.
https://list.orgmode.org/87v8rmd53g.fsf@localhost/
2022-07-29 21:02:23 +08:00
Ihor Radchenko d2775da08d
test-ol/org-toggle-link-display: Fix compatibility with old Emacs
* testing/lisp/test-ol.el (test-ol/org-toggle-link-display): Use
back-compatible `org-xor' instead of `xor'.
2022-04-25 19:40:12 +08:00
Ihor Radchenko 6d4e65a124
Add org-fold-related tests 2022-04-25 19:40:01 +08:00
Ihor Radchenko f313b81841 Improve org-link-plain-re
* lisp/ol.el (org-link-make-regexps): Allow URLs with up to two
levels of nested brackets.

* lisp/org.el (org-link-plain-re): Update docstring.

* testing/lisp/test-ol.el: Add tests for the plain link regular
expression.

(org-link-plain-re): Update docstring.  Now,

Now, URLs like [1] can be matched.  The new regexp is based on [2].
The docstring of `org-link-plain-re'  explicitly mentions that the
regexp must contain groups for the link type and the path.

[1] https://doi.org/10.1016/0160-791x(79)90023-x
[2] https://daringfireball.net/2010/07/improved_regex_for_matching_urls
2021-05-15 10:33:23 +02:00
Nicolas Goaziou 7a78eb1be0 ol: Fix some corner cases when normalizing context in links
* lisp/ol.el (org-link--normalize-string): Handle blanks between
special characters.
(org-link-heading-search-string): Small refactoring.
* testing/lisp/test-ol.el (test-ol/store-link): Add tests.
2020-03-26 22:57:16 +01:00
Nicolas Goaziou 97e415c5df ol: Do not save tags when storing a link from a headline
* lisp/ol.el (org-link-heading-search-string): Assume optional
argument is already valid.  Remove TODO keyword, priority cookie,
COMMENT keyword, and tags.
(org-link-search): Remove COMMENT keyword.
* testing/lisp/test-ol.el (test-ol/store-link): Add tests.
2020-03-09 22:23:11 +01:00
Nicolas Goaziou 546cbad531 Link syntax require to escape every square bracket
* lisp/ol.el (org-link-make-regexps): Update regexp to forbid any
un-escaped square bracket in the URI.
(org-link-escape):
(org-link-unescape):
* testing/lisp/test-ol.el (test-ol/escape):
(test-ol/unescape):
(test-ol/store-link):
* testing/lisp/test-org.el (test-org/custom-id):
(test-org/fuzzy-links):
* testing/lisp/test-ox.el (test-org-export/resolve-fuzzy-link): Adapt
to new syntax.
* doc/org-manual.org (Link Format): Update documentation.

The new syntax allowed un-escaped opening square brackets in the URI
part of bracket links. Unfortunately, it led to bug as described here:

  <https://lists.gnu.org/archive/html/emacs-orgmode/2019-12/msg00312.html>

Now, we require to escape every square bracket in the URI.
2019-12-22 14:52:53 +01:00
Nicolas Goaziou 09a1a24b73 ol: Fix `org-previous-link' skipping links
* lisp/ol.el (org-next-link): Do not skip links when searching
  backwards.

Reported-by: stardiviner <numbchild@gmail.com>
<http://lists.gnu.org/r/emacs-orgmode/2019-04/msg00022.html>
2019-04-10 15:26:46 +02:00
Nicolas Goaziou 3375f039dd ol: Fix `org-next-link' in an item tag
* lisp/ol.el (org-next-link): Fix `org-next-link' in an item tag.
* testing/lisp/test-ol.el (test-ol/next-link): Add test.
2019-04-04 15:52:41 +02:00
Nicolas Goaziou 2b00d62816 Change bracket link escape syntax
* contrib/lisp/org-link-edit.el (org-link-edit--link-data):
* lisp/ob-tangle.el (org-babel-tangle-comment-links): Update match-group.
(org-babel-detangle): Remove unnecessary `org-link-escape' call.
(org-babel-tangle-jump-to-org): Update match group.
(org-link-url-hexify):
(org-link-escape-chars): Remove variables.
* lisp/ol.el (org-link--decode-compound): Renamed from
  `org-link--unescape-compound'.
(org-link--decode-single-byte-sequence): Renamed from
`org-link--unescape-single-byte-sequence'.
(org-link-make-regexps): Update `org-link-bracket-re' syntax.
(org-link-encode): New function, renamed from `org-link-escape'.
(org-link-decode): New function, renamed from `org-link-unescape'.
(org-link-escape):
(org-link-unescape): Use new escape syntax.
(org-link-make-string): Apply new escaping rules.
(org-link-display-format):
(org-insert-link): Update match group.
* lisp/org-agenda.el (org-diary):
(org-agenda-format-item):
(org-agenda-to-appt): Update match group.
* lisp/org-clock.el (org-clocktable-write-default): Update match group.
* lisp/org-element.el (org-element-link-parser): Update match group.
* lisp/org-mobile.el (org-mobile-escape-olp):
(org-mobile-locate-entry): Apply function renaming.
* lisp/org-protocol.el (org-protocol-split-data):
(org-protocol-parse-parameters): Apply function renaming.
* lisp/org.el (org-refile): Update match group.
* testing/README (Interactive testing from within Emacs): Fix
  examples.
* testing/lisp/test-ol.el (test-ol/encode): Merge old escape tests.
(test-ol/decode): Merge old unescape tests.
(test-ol/escape):
(test-ol/unescape):
(test-ol/make-string): New tests.
* testing/lisp/test-org-clock.el (test-org-clock/clocktable/link):
* testing/lisp/test-org.el (test-org/custom-id):
(test-org/fuzzy-links):
* testing/lisp/test-ox.el (test-org-export/resolve-fuzzy-link): Update
  tests.
2019-03-10 18:00:36 +01:00
Nicolas Goaziou 4ff8947ea8 Fix `org-(next|previous)-link'
* lisp/ol.el (org-next-link): Rewrite function.
* testing/lisp/test-ol.el (test-ol/next-link):
(test-ol/previous-link): New tests.
2019-03-10 18:00:36 +01:00
Nicolas Goaziou 8ffe341989 Move link tests to a dedicated file
* testing/lisp/test-org.el: Move test to the...
* testing/lisp/test-ol.el: ... new file.
2019-03-10 18:00:36 +01:00