1
0
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-11-21 06:55:35 +00:00
org-mode/lisp/org-pcomplete.el

464 lines
16 KiB
EmacsLisp
Raw Normal View History

2016-06-21 21:14:49 +00:00
;;; org-pcomplete.el --- In-buffer Completion Code -*- lexical-binding: t; -*-
;; Copyright (C) 2004-2024 Free Software Foundation, Inc.
;;
;; Author: Carsten Dominik <carsten.dominik@gmail.com>
;; John Wiegley <johnw at gnu dot org>
;; Keywords: outlines, hypermedia, calendar, text
;; URL: https://orgmode.org
;;
;; This file is part of GNU Emacs.
;;
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; This library implementes completion support in Org mode buffers.
;;; Code:
;;;; Require other packages
(require 'org-macs)
(org-assert-version)
(require 'org-macs)
(require 'org-compat)
(require 'pcomplete)
2018-10-18 13:49:32 +00:00
(declare-function org-at-heading-p "org" (&optional ignored))
2020-06-03 14:52:20 +00:00
(declare-function org-babel-combine-header-arg-lists "ob-core" (original &rest others))
(declare-function org-babel-get-src-block-info "ob-core" (&optional no-eval datum))
2018-10-18 13:49:32 +00:00
(declare-function org-before-first-heading-p "org" ())
(declare-function org-buffer-property-keys "org" (&optional specials defaults columns))
2022-01-06 17:39:05 +00:00
(declare-function org-element-at-point "org-element" (&optional pom cached-only))
(declare-function org-element-property "org-element-ast" (property node &optional dflt force-undefer))
(declare-function org-element-end "org-element" (node))
(declare-function org-element-type-p "org-element-ast" (node types))
2018-10-18 13:49:32 +00:00
(declare-function org-end-of-meta-data "org" (&optional full))
(declare-function org-entry-properties "org" (&optional pom which))
2018-10-18 13:49:32 +00:00
(declare-function org-export-backend-options "ox" (cl-x) t)
(declare-function org-get-buffer-tags "org" ())
(declare-function org-get-export-keywords "org" ())
(declare-function org-get-heading "org" (&optional no-tags no-todo no-priority no-comment))
(declare-function org-get-tags "org" (&optional pos local))
Move link-related core functions out of "org.el" * contrib/lisp/org-wl.el (org-wl-store-link-message): * lisp/Makefile (clean-install): * lisp/ob-core.el (org-link-bracket-re): (org-babel-open-src-block-result): (org-babel-read-element): (org-babel-read-link): (org-babel-result-end): * lisp/ob-tangle.el (org-link-bracket-re): (org-babel-tangle-single-block): (org-link-analytic-bracket-re): (org-babel-detangle): (org-babel-tangle-jump-to-org): * lisp/ol.el: * lisp/org-agenda.el (org-agenda-get-some-entry-text): (org-diary): (org-agenda-format-item): (org-agenda-open-link): (org-agenda-switch-to): (org-agenda-to-appt): * lisp/org-bbdb.el (org-bbdb-store-link): * lisp/org-bibtex.el (org-bibtex-store-link): * lisp/org-capture.el (org-capture-fill-template): * lisp/org-clock.el (org-clocktable-write-default): (org-clock-get-table-data): * lisp/org-compat.el (org-doi-server-url): (org-email-link-description-format): (org-make-link-description-function): (org-from-is-user-regexp): (org-descriptive-links): (org-url-hexify-p): (org-context-in-file-links): (org-keep-stored-link-after-insertion): (org-display-internal-link-with-indirect-buffer): (org-confirm-shell-link-function): (org-confirm-shell-link-not-regexp): (org-confirm-elisp-link-function): (org-confirm-elisp-link-not-regexp): (org-file-complete-link): (org-email-link-description): (org-make-link-string): (org-store-link-props): (org-add-link-props): (org-make-link-regexps): (org-angle-link-re): (org-plain-link-re): (org-bracket-link-regexp): (org-bracket-link-analytic-regexp): (org-any-link-re): * lisp/org-docview.el (org-docview-store-link): (org-docview-complete-link): * lisp/org-element.el (org-element-link-parser): * lisp/org-eshell.el (org-eshell-store-link): * lisp/org-eww.el (org-eww-store-link): (org-eww-copy-for-org-mode): * lisp/org-footnote.el (org-footnote-next-reference-or-definition): * lisp/org-gnus.el (org-gnus-article-link): (org-gnus-store-link): * lisp/org-id.el (org-id-store-link): * lisp/org-info.el (org-info-store-link): * lisp/org-irc.el (org-irc-erc-store-link): * lisp/org-mhe.el (org-mhe-store-link): * lisp/org-pcomplete.el (pcomplete/org-mode/searchhead): * lisp/org-protocol.el (org-protocol-do-capture): * lisp/org-rmail.el (org-rmail-store-link): * lisp/org-w3m.el (org-w3m-store-link): (org-w3m-copy-for-org-mode):
2018-11-26 23:04:41 +00:00
(declare-function org-link-heading-search-string "ol" (&optional string))
(declare-function org-tag-alist-to-string "org" (alist &optional skip-key))
(declare-function org-time-stamp-format "org" (&optional with-time inactive custom))
2020-06-03 14:52:20 +00:00
(defvar org-babel-common-header-args-w-values)
2018-10-18 13:49:32 +00:00
(defvar org-current-tag-alist)
(defvar org-priority-default)
(defvar org-drawer-regexp)
2018-10-18 13:49:32 +00:00
(defvar org-element-affiliated-keywords)
(defvar org-entities)
(defvar org-export-default-language)
(defvar org-export-exclude-tags)
(defvar org-export-select-tags)
(defvar org-file-tags)
(defvar org-priority-highest)
2018-10-18 13:49:32 +00:00
(defvar org-link-abbrev-alist)
(defvar org-link-abbrev-alist-local)
(defvar org-priority-lowest)
2018-10-18 13:49:32 +00:00
(defvar org-options-keywords)
(defvar org-outline-regexp)
(defvar org-property-re)
2018-10-18 13:49:32 +00:00
(defvar org-startup-options)
2018-11-30 20:20:39 +00:00
(defvar org-tag-re)
2018-10-18 13:49:32 +00:00
(defvar org-todo-keywords-1)
(defvar org-todo-line-regexp)
2018-10-18 16:09:41 +00:00
;;; Internal Functions
(defun org-thing-at-point ()
"Examine the thing at point and let the caller know what it is.
The return value is a string naming the thing at point."
(let ((line-to-here (org-current-line-string t))
(case-fold-search t))
(cond
;; Parameters on a clock table opening line.
((org-match-line "[ \t]*#\\+BEGIN: clocktable[ \t]")
(cons "block-option" "clocktable"))
;; Flags and parameters on a source block opening line.
((org-match-line "[ \t]*#\\+BEGIN_SRC[ \t]")
(cons "block-option" "src"))
;; Value for a known keyword.
((org-match-line "[ \t]*#\\+\\(\\S-+\\):")
(cons "file-option" (match-string-no-properties 1)))
;; Keyword name.
((and (org-match-line "[ \t]*#\\+[a-zA-Z_]*$")
(looking-at-p "[ \t]*$"))
(cons "file-option" nil))
;; Link abbreviation.
((save-excursion
(skip-chars-backward "-A-Za-z0-9_")
(and (eq ?\[ (char-before))
(eq ?\[ (char-before (1- (point))))))
(cons "link" nil))
;; Entities. Some of them accept numbers, but only at their end.
;; So, we first skip numbers, then letters.
((eq ?\\ (save-excursion
(skip-chars-backward "0-9")
(skip-chars-backward "a-zA-Z")
(char-before)))
(cons "tex" nil))
;; Tags on a headline.
((and (org-match-line
(format "\\*+ \\(?:.+? \\)?\\(:\\)\\(\\(?::\\|%s\\)+\\)?[ \t]*$"
org-tag-re))
(or (org-point-in-group (point) 2)
(= (point) (match-end 1))))
(cons "tag" nil))
;; TODO keywords on an empty headline.
((and (string-match "^\\*+ +\\S-*$" line-to-here)
(looking-at-p "[ \t]*$"))
(cons "todo" nil))
;; Heading after a star for search strings or links.
((save-excursion
(skip-chars-backward "^*" (line-beginning-position))
(and (eq ?* (char-before))
(eq (char-before (1- (point))) '?\[)
(eq (char-before (- (point) 2)) '?\[)))
(cons "searchhead" nil))
;; Property or drawer name, depending on point. If point is at
;; a valid location for a node property, offer completion on all
;; node properties in the buffer. Otherwise, offer completion on
;; all drawer names, including "PROPERTIES".
((and (string-match "^[ \t]*:\\S-*$" line-to-here)
(looking-at-p "[ \t]*$"))
(let ((origin (line-beginning-position)))
(if (org-before-first-heading-p) (cons "drawer" nil)
(save-excursion
(org-end-of-meta-data)
(if (or (= origin (point))
(not (org-match-line "[ \t]*:PROPERTIES:[ \t]*$")))
(cons "drawer" nil)
(while (org-match-line org-property-re)
(forward-line))
(if (= origin (point)) (cons "prop" nil)
(cons "drawer" nil)))))))
(t nil))))
2018-10-18 16:09:41 +00:00
(defun org-pcomplete-case-double (list)
"Return list with both upcase and downcase version of all strings in LIST."
(let (e res)
(while (setq e (pop list))
(setq res (cons (downcase e) (cons (upcase e) res))))
(nreverse res)))
;;; Completion API
(defun org-command-at-point ()
"Return the qualified name of the Org completion entity at point.
When completing for #+STARTUP, for example, this function returns
\"file-option/startup\"."
(let ((thing (org-thing-at-point)))
(cond
((string= "file-option" (car thing))
(concat (car thing)
(and (cdr thing) (concat "/" (downcase (cdr thing))))))
((string= "block-option" (car thing))
(concat (car thing) "/" (downcase (cdr thing))))
(t (car thing)))))
(defun org-parse-arguments ()
"Parse whitespace separated arguments in the current region."
(if (equal (cons "searchhead" nil) (org-thing-at-point))
;; [[* foo<point> bar link::search option.
;; Arguments are not simply space-separated.
(save-excursion
(let ((origin (point)))
(skip-chars-backward "^*" (line-beginning-position))
(cons (list (buffer-substring-no-properties (point) origin))
(list (point)))))
(let ((begin (line-beginning-position))
(end (line-end-position))
begins args)
(save-restriction
(narrow-to-region begin end)
(save-excursion
(goto-char (point-min))
(while (not (eobp))
(skip-chars-forward " \t\n[")
(setq begins (cons (point) begins))
(skip-chars-forward "^ \t\n[")
(setq args (cons (buffer-substring-no-properties
(car begins) (point))
args)))
(cons (reverse args) (reverse begins)))))))
(defun org-pcomplete-initial ()
"Call the right completion function for first argument completions."
(ignore
(funcall (or (pcomplete-find-completion-function
(car (org-thing-at-point)))
pcomplete-default-completion-function))))
2018-10-18 16:09:41 +00:00
;;; Completion functions
(defun pcomplete/org-mode/file-option ()
"Complete against all valid file options."
(require 'org-element)
(pcomplete-here
(org-pcomplete-case-double
(append (mapcar (lambda (keyword) (concat keyword " "))
org-options-keywords)
(mapcar (lambda (keyword) (concat keyword ": "))
org-element-affiliated-keywords)
(let (block-names)
(dolist (name
'("CENTER" "COMMENT" "EXAMPLE" "EXPORT" "QUOTE" "SRC"
"VERSE")
block-names)
(push (format "END_%s" name) block-names)
(push (concat "BEGIN_"
name
;; Since language is compulsory in
;; export blocks source blocks, add
;; a space.
(and (member name '("EXPORT" "SRC")) " "))
block-names)
(push (format "ATTR_%s: " name) block-names)))
(mapcar (lambda (keyword) (concat keyword ": "))
(org-get-export-keywords))))
(substring pcomplete-stub 2)))
(defun pcomplete/org-mode/file-option/author ()
"Complete arguments for the #+AUTHOR file option."
(pcomplete-here (list user-full-name)))
(defun pcomplete/org-mode/file-option/date ()
"Complete arguments for the #+DATE file option."
Refactor `org-time-stamp-custom-formats' and `org-time-stamp-formats' * lisp/org.el (org-time-stamp-formats): * lisp/org.el (org-time-stamp-custom-formats): Change the default values stripping leading "<" and trailing ">". Update the docstring explaining the format and that leading and trailing brackets are now ignored. Update the :type specification to more precise. (org-time-stamp-format): Update the argument list and docstring allowing to use the function more flexibly to find the time stamp format for both `org-time-stamp-formats' and `org-time-stamp-custom-formats'. Rename `long' argument to more accurate `with-time'. Ignore brackets in the `org-time-stamp-formats' and `org-time-stamp-custom-formats'. Allow `inactive' argument to be `no-brackets' (org-format-timestamp): (org-read-date-display): (org-insert-time-stamp): (org-display-custom-time): (org-timestamp-translate): * lisp/org-compat.el (org-timestamp-format): Rename `org-timestamp-format' to `org-format-timestamp'. The old variant is too similar with other `org-time-stamp-format' function. Also, use `org-time-stamp-format' to determine the timestamp format instead of using `org-time-stamp-formats' directly. * lisp/ol.el (org-store-link): * lisp/org-agenda.el (org-agenda-get-timestamps): (org-agenda-get-progress): * lisp/org-archive.el (org-archive-subtree): (org-archive-to-archive-sibling): * lisp/org-clock.el (org-clock-special-range): * lisp/org-colview.el (org-colview-construct-allowed-dates): * lisp/org-element.el (org-element-timestamp-interpreter): * lisp/org-macro.el (org-macro--find-date): * lisp/org-pcomplete.el (pcomplete/org-mode/file-option/date): * lisp/ox-odt.el (org-odt--format-timestamp): (org-odt-template): * lisp/ox.el (org-export-get-date): * testing/lisp/test-org.el (test-org/timestamp-format): Use `org-time-stamp-format' instead of directly examining `org-time-stamp-custom-formats' and `org-time-stamp-formats'. Use the new function name `org-format-timestamp'. * etc/ORG-NEWS (Default values and interpretations of ~org-time-stamp-formats~ and ~org-time-stamp-custom-formats~ are changed): (~org-timestamp-format~ is renamed to ~org-format-timestamp~): (Updated argument list in ~org-time-stamp-format~): Document the user-facing changes. This commit documents and unifies previously undocumented assumptions about the values of `org-time-stamp-formats' and `org-time-stamp-custom-formats'. Instead of fiddling with leading/trailing brackets in the values, expedite the time format calculation to `org-time-stamp-format'. The undocumented assumption about brackets in user option `org-time-stamp-custom-formats' is not relaxed making the docstring correct. Reported-by: Uwe Brauer <oub@mat.ucm.es> Link: https://orgmode.org/list/87k04ppp1t.fsf@localhost
2022-11-07 07:05:37 +00:00
(pcomplete-here (list (format-time-string (org-time-stamp-format)))))
(defun pcomplete/org-mode/file-option/email ()
"Complete arguments for the #+EMAIL file option."
(pcomplete-here (list user-mail-address)))
(defun pcomplete/org-mode/file-option/exclude_tags ()
"Complete arguments for the #+EXCLUDE_TAGS file option."
(require 'ox)
(pcomplete-here
(and org-export-exclude-tags
(list (mapconcat #'identity org-export-exclude-tags " ")))))
(defun pcomplete/org-mode/file-option/filetags ()
"Complete arguments for the #+FILETAGS file option."
(pcomplete-here (and org-file-tags (mapconcat #'identity org-file-tags " "))))
(defun pcomplete/org-mode/file-option/language ()
"Complete arguments for the #+LANGUAGE file option."
(require 'ox)
(pcomplete-here
Many small code improvements * lisp/org-capture.el (org-capture-member): Make obsolete; the old definition was identical to ‘org-capture-get’ anyway. (org-capture-mode-map): Move the calls to ‘define-key’ up to where the variable is defined. (org-capture-mode-hook): Small docstring tweak. (org-capture-mode): Fix typo in mode lighter. (org-capture-set-target-location, org-capture-place-item): (org-capture-place-plain-text, org-capture-narrow): (org-capture-empty-lines-after): (org-capture-import-remember-templates): ‘if’ without else -> ‘when’ * lisp/org-colview.el (org-columns-edit-value): Change an error to a user-error. (org-columns-uncompile-format): Improve docstring. * lisp/org-compat.el (org-remove-from-invisibility-spec): Make obsolete, the underlying emacs function exists since 1997, commit 31aa282e. (org-in-invisibility-spec-p, org-count-lines): ‘if’ without else -> ‘when’. * lisp/org-element.el (org-element-swap-A-B): * lisp/org-entities.el (org-entities-create-table): * lisp/org-list.el (org-insert-item): * lisp/org-macs.el (org-with-point-at, org-base-buffer): (org-preserve-local-variables, org-overlay-display): (org-overlay-before-string): ‘if’ without else -> ‘when’. * lisp/org-eshell.el (org-eshell-open): Fix docstring typo. * lisp/org-pcomplete.el (pcomplete/org-mode/file-option/language): (pcomplete/org-mode/file-option/startup): (pcomplete/org-mode/file-option/options): (pcomplete/org-mode/file-option/infojs_opt): (pcomplete/org-mode/link, pcomplete/org-mode/tex): (pcomplete/org-mode/todo, pcomplete/org-mode/searchhead): (pcomplete/org-mode/tag, pcomplete/org-mode/prop): Avoid the formerly misspelled ‘pcomplete-uniqify-list’ function. It has a defalias in emacs >= 27; we add our own for older emacsen. (pcomplete/org-mode/file-option/bind): ‘if’ without else -> ‘when’. * lisp/org-protocol.el (org-protocol-capture): (org-protocol-convert-query-to-plist): ‘if’ without else -> ‘when’. (org-protocol-do-capture): Pacify byte compiler, simplify conditional logic. * lisp/org-table.el (org-table-create-with-table.el): Simplify conditional logic. (org-table-create, org-table-convert-region, org-table-next-field): (org-table-beginning-of-field, org-table-end-of-field): * lisp/org-w3m.el (org-w3m-copy-for-org-mode): ‘if’ without else -> ‘when’. * lisp/org.el (org-babel-do-load-languages, org-previous-link): (org-refile): Use ‘(foo ...)’ instead of ‘(funcall 'foo ...)’. (org-add-log-note): Convert a long cond into a cl-case. (org-priority): Improve docstring, show a deprecation warning if the ‘show’ argument is passed (which was previously silently ignored). Also, use ?\s instead of ?\ as a character literal for space. (org-fast-tag-insert): Fix docstring typo. (org-fill-element): ‘if’ without else -> ‘when’. (org-on-target-p): Remove ancient compatibility alias.
2018-05-10 01:02:35 +00:00
(pcomplete-uniquify-list
(list org-export-default-language "en"))))
(defun pcomplete/org-mode/file-option/priorities ()
"Complete arguments for the #+PRIORITIES file option."
(pcomplete-here (list (format "%c %c %c"
org-priority-highest
org-priority-lowest
org-priority-default))))
(defun pcomplete/org-mode/file-option/select_tags ()
"Complete arguments for the #+SELECT_TAGS file option."
(require 'ox)
(pcomplete-here
(and org-export-select-tags
(list (mapconcat #'identity org-export-select-tags " ")))))
(defun pcomplete/org-mode/file-option/startup ()
"Complete arguments for the #+STARTUP file option."
(while (pcomplete-here
Many small code improvements * lisp/org-capture.el (org-capture-member): Make obsolete; the old definition was identical to ‘org-capture-get’ anyway. (org-capture-mode-map): Move the calls to ‘define-key’ up to where the variable is defined. (org-capture-mode-hook): Small docstring tweak. (org-capture-mode): Fix typo in mode lighter. (org-capture-set-target-location, org-capture-place-item): (org-capture-place-plain-text, org-capture-narrow): (org-capture-empty-lines-after): (org-capture-import-remember-templates): ‘if’ without else -> ‘when’ * lisp/org-colview.el (org-columns-edit-value): Change an error to a user-error. (org-columns-uncompile-format): Improve docstring. * lisp/org-compat.el (org-remove-from-invisibility-spec): Make obsolete, the underlying emacs function exists since 1997, commit 31aa282e. (org-in-invisibility-spec-p, org-count-lines): ‘if’ without else -> ‘when’. * lisp/org-element.el (org-element-swap-A-B): * lisp/org-entities.el (org-entities-create-table): * lisp/org-list.el (org-insert-item): * lisp/org-macs.el (org-with-point-at, org-base-buffer): (org-preserve-local-variables, org-overlay-display): (org-overlay-before-string): ‘if’ without else -> ‘when’. * lisp/org-eshell.el (org-eshell-open): Fix docstring typo. * lisp/org-pcomplete.el (pcomplete/org-mode/file-option/language): (pcomplete/org-mode/file-option/startup): (pcomplete/org-mode/file-option/options): (pcomplete/org-mode/file-option/infojs_opt): (pcomplete/org-mode/link, pcomplete/org-mode/tex): (pcomplete/org-mode/todo, pcomplete/org-mode/searchhead): (pcomplete/org-mode/tag, pcomplete/org-mode/prop): Avoid the formerly misspelled ‘pcomplete-uniqify-list’ function. It has a defalias in emacs >= 27; we add our own for older emacsen. (pcomplete/org-mode/file-option/bind): ‘if’ without else -> ‘when’. * lisp/org-protocol.el (org-protocol-capture): (org-protocol-convert-query-to-plist): ‘if’ without else -> ‘when’. (org-protocol-do-capture): Pacify byte compiler, simplify conditional logic. * lisp/org-table.el (org-table-create-with-table.el): Simplify conditional logic. (org-table-create, org-table-convert-region, org-table-next-field): (org-table-beginning-of-field, org-table-end-of-field): * lisp/org-w3m.el (org-w3m-copy-for-org-mode): ‘if’ without else -> ‘when’. * lisp/org.el (org-babel-do-load-languages, org-previous-link): (org-refile): Use ‘(foo ...)’ instead of ‘(funcall 'foo ...)’. (org-add-log-note): Convert a long cond into a cl-case. (org-priority): Improve docstring, show a deprecation warning if the ‘show’ argument is passed (which was previously silently ignored). Also, use ?\s instead of ?\ as a character literal for space. (org-fast-tag-insert): Fix docstring typo. (org-fill-element): ‘if’ without else -> ‘when’. (org-on-target-p): Remove ancient compatibility alias.
2018-05-10 01:02:35 +00:00
(let ((opts (pcomplete-uniquify-list
(mapcar #'car org-startup-options))))
;; Some options are mutually exclusive, and shouldn't be completed
;; against if certain other options have already been seen.
(dolist (arg pcomplete-args)
(cond
((string= arg "hidestars")
(setq opts (delete "showstars" opts)))))
opts))))
(defun pcomplete/org-mode/file-option/tags ()
"Complete arguments for the #+TAGS file option."
(pcomplete-here
(list (org-tag-alist-to-string org-current-tag-alist))))
(defun pcomplete/org-mode/file-option/title ()
"Complete arguments for the #+TITLE file option."
(pcomplete-here
(let ((visited-file (buffer-file-name (buffer-base-buffer))))
(list (or (and visited-file
(file-name-sans-extension
(file-name-nondirectory visited-file)))
(buffer-name (buffer-base-buffer)))))))
(defun pcomplete/org-mode/file-option/options ()
"Complete arguments for the #+OPTIONS file option."
(while (pcomplete-here
Many small code improvements * lisp/org-capture.el (org-capture-member): Make obsolete; the old definition was identical to ‘org-capture-get’ anyway. (org-capture-mode-map): Move the calls to ‘define-key’ up to where the variable is defined. (org-capture-mode-hook): Small docstring tweak. (org-capture-mode): Fix typo in mode lighter. (org-capture-set-target-location, org-capture-place-item): (org-capture-place-plain-text, org-capture-narrow): (org-capture-empty-lines-after): (org-capture-import-remember-templates): ‘if’ without else -> ‘when’ * lisp/org-colview.el (org-columns-edit-value): Change an error to a user-error. (org-columns-uncompile-format): Improve docstring. * lisp/org-compat.el (org-remove-from-invisibility-spec): Make obsolete, the underlying emacs function exists since 1997, commit 31aa282e. (org-in-invisibility-spec-p, org-count-lines): ‘if’ without else -> ‘when’. * lisp/org-element.el (org-element-swap-A-B): * lisp/org-entities.el (org-entities-create-table): * lisp/org-list.el (org-insert-item): * lisp/org-macs.el (org-with-point-at, org-base-buffer): (org-preserve-local-variables, org-overlay-display): (org-overlay-before-string): ‘if’ without else -> ‘when’. * lisp/org-eshell.el (org-eshell-open): Fix docstring typo. * lisp/org-pcomplete.el (pcomplete/org-mode/file-option/language): (pcomplete/org-mode/file-option/startup): (pcomplete/org-mode/file-option/options): (pcomplete/org-mode/file-option/infojs_opt): (pcomplete/org-mode/link, pcomplete/org-mode/tex): (pcomplete/org-mode/todo, pcomplete/org-mode/searchhead): (pcomplete/org-mode/tag, pcomplete/org-mode/prop): Avoid the formerly misspelled ‘pcomplete-uniqify-list’ function. It has a defalias in emacs >= 27; we add our own for older emacsen. (pcomplete/org-mode/file-option/bind): ‘if’ without else -> ‘when’. * lisp/org-protocol.el (org-protocol-capture): (org-protocol-convert-query-to-plist): ‘if’ without else -> ‘when’. (org-protocol-do-capture): Pacify byte compiler, simplify conditional logic. * lisp/org-table.el (org-table-create-with-table.el): Simplify conditional logic. (org-table-create, org-table-convert-region, org-table-next-field): (org-table-beginning-of-field, org-table-end-of-field): * lisp/org-w3m.el (org-w3m-copy-for-org-mode): ‘if’ without else -> ‘when’. * lisp/org.el (org-babel-do-load-languages, org-previous-link): (org-refile): Use ‘(foo ...)’ instead of ‘(funcall 'foo ...)’. (org-add-log-note): Convert a long cond into a cl-case. (org-priority): Improve docstring, show a deprecation warning if the ‘show’ argument is passed (which was previously silently ignored). Also, use ?\s instead of ?\ as a character literal for space. (org-fast-tag-insert): Fix docstring typo. (org-fill-element): ‘if’ without else -> ‘when’. (org-on-target-p): Remove ancient compatibility alias.
2018-05-10 01:02:35 +00:00
(pcomplete-uniquify-list
(append
;; Hard-coded OPTION items always available.
'("H:" "\\n:" "num:" "timestamp:" "arch:" "author:" "c:"
"creator:" "date:" "d:" "email:" "*:" "e:" "::" "f:"
"inline:" "tex:" "p:" "pri:" "':" "-:" "stat:" "^:" "toc:"
"|:" "tags:" "tasks:" "<:" "todo:")
;; OPTION items from registered backends.
(let (items)
(dolist (backend (bound-and-true-p
org-export-registered-backends))
(dolist (option (org-export-backend-options backend))
(let ((item (nth 2 option)))
(when item (push (concat item ":") items)))))
items))))))
(defun pcomplete/org-mode/file-option/infojs_opt ()
"Complete arguments for the #+INFOJS_OPT file option."
(while (pcomplete-here
Many small code improvements * lisp/org-capture.el (org-capture-member): Make obsolete; the old definition was identical to ‘org-capture-get’ anyway. (org-capture-mode-map): Move the calls to ‘define-key’ up to where the variable is defined. (org-capture-mode-hook): Small docstring tweak. (org-capture-mode): Fix typo in mode lighter. (org-capture-set-target-location, org-capture-place-item): (org-capture-place-plain-text, org-capture-narrow): (org-capture-empty-lines-after): (org-capture-import-remember-templates): ‘if’ without else -> ‘when’ * lisp/org-colview.el (org-columns-edit-value): Change an error to a user-error. (org-columns-uncompile-format): Improve docstring. * lisp/org-compat.el (org-remove-from-invisibility-spec): Make obsolete, the underlying emacs function exists since 1997, commit 31aa282e. (org-in-invisibility-spec-p, org-count-lines): ‘if’ without else -> ‘when’. * lisp/org-element.el (org-element-swap-A-B): * lisp/org-entities.el (org-entities-create-table): * lisp/org-list.el (org-insert-item): * lisp/org-macs.el (org-with-point-at, org-base-buffer): (org-preserve-local-variables, org-overlay-display): (org-overlay-before-string): ‘if’ without else -> ‘when’. * lisp/org-eshell.el (org-eshell-open): Fix docstring typo. * lisp/org-pcomplete.el (pcomplete/org-mode/file-option/language): (pcomplete/org-mode/file-option/startup): (pcomplete/org-mode/file-option/options): (pcomplete/org-mode/file-option/infojs_opt): (pcomplete/org-mode/link, pcomplete/org-mode/tex): (pcomplete/org-mode/todo, pcomplete/org-mode/searchhead): (pcomplete/org-mode/tag, pcomplete/org-mode/prop): Avoid the formerly misspelled ‘pcomplete-uniqify-list’ function. It has a defalias in emacs >= 27; we add our own for older emacsen. (pcomplete/org-mode/file-option/bind): ‘if’ without else -> ‘when’. * lisp/org-protocol.el (org-protocol-capture): (org-protocol-convert-query-to-plist): ‘if’ without else -> ‘when’. (org-protocol-do-capture): Pacify byte compiler, simplify conditional logic. * lisp/org-table.el (org-table-create-with-table.el): Simplify conditional logic. (org-table-create, org-table-convert-region, org-table-next-field): (org-table-beginning-of-field, org-table-end-of-field): * lisp/org-w3m.el (org-w3m-copy-for-org-mode): ‘if’ without else -> ‘when’. * lisp/org.el (org-babel-do-load-languages, org-previous-link): (org-refile): Use ‘(foo ...)’ instead of ‘(funcall 'foo ...)’. (org-add-log-note): Convert a long cond into a cl-case. (org-priority): Improve docstring, show a deprecation warning if the ‘show’ argument is passed (which was previously silently ignored). Also, use ?\s instead of ?\ as a character literal for space. (org-fast-tag-insert): Fix docstring typo. (org-fill-element): ‘if’ without else -> ‘when’. (org-on-target-p): Remove ancient compatibility alias.
2018-05-10 01:02:35 +00:00
(pcomplete-uniquify-list
(mapcar (lambda (item) (format "%s:" (car item)))
(bound-and-true-p org-html-infojs-opts-table))))))
(defun pcomplete/org-mode/file-option/bind ()
"Complete arguments for the #+BIND file option, which are variable names."
(let (vars)
(mapatoms
Many small code improvements * lisp/org-capture.el (org-capture-member): Make obsolete; the old definition was identical to ‘org-capture-get’ anyway. (org-capture-mode-map): Move the calls to ‘define-key’ up to where the variable is defined. (org-capture-mode-hook): Small docstring tweak. (org-capture-mode): Fix typo in mode lighter. (org-capture-set-target-location, org-capture-place-item): (org-capture-place-plain-text, org-capture-narrow): (org-capture-empty-lines-after): (org-capture-import-remember-templates): ‘if’ without else -> ‘when’ * lisp/org-colview.el (org-columns-edit-value): Change an error to a user-error. (org-columns-uncompile-format): Improve docstring. * lisp/org-compat.el (org-remove-from-invisibility-spec): Make obsolete, the underlying emacs function exists since 1997, commit 31aa282e. (org-in-invisibility-spec-p, org-count-lines): ‘if’ without else -> ‘when’. * lisp/org-element.el (org-element-swap-A-B): * lisp/org-entities.el (org-entities-create-table): * lisp/org-list.el (org-insert-item): * lisp/org-macs.el (org-with-point-at, org-base-buffer): (org-preserve-local-variables, org-overlay-display): (org-overlay-before-string): ‘if’ without else -> ‘when’. * lisp/org-eshell.el (org-eshell-open): Fix docstring typo. * lisp/org-pcomplete.el (pcomplete/org-mode/file-option/language): (pcomplete/org-mode/file-option/startup): (pcomplete/org-mode/file-option/options): (pcomplete/org-mode/file-option/infojs_opt): (pcomplete/org-mode/link, pcomplete/org-mode/tex): (pcomplete/org-mode/todo, pcomplete/org-mode/searchhead): (pcomplete/org-mode/tag, pcomplete/org-mode/prop): Avoid the formerly misspelled ‘pcomplete-uniqify-list’ function. It has a defalias in emacs >= 27; we add our own for older emacsen. (pcomplete/org-mode/file-option/bind): ‘if’ without else -> ‘when’. * lisp/org-protocol.el (org-protocol-capture): (org-protocol-convert-query-to-plist): ‘if’ without else -> ‘when’. (org-protocol-do-capture): Pacify byte compiler, simplify conditional logic. * lisp/org-table.el (org-table-create-with-table.el): Simplify conditional logic. (org-table-create, org-table-convert-region, org-table-next-field): (org-table-beginning-of-field, org-table-end-of-field): * lisp/org-w3m.el (org-w3m-copy-for-org-mode): ‘if’ without else -> ‘when’. * lisp/org.el (org-babel-do-load-languages, org-previous-link): (org-refile): Use ‘(foo ...)’ instead of ‘(funcall 'foo ...)’. (org-add-log-note): Convert a long cond into a cl-case. (org-priority): Improve docstring, show a deprecation warning if the ‘show’ argument is passed (which was previously silently ignored). Also, use ?\s instead of ?\ as a character literal for space. (org-fast-tag-insert): Fix docstring typo. (org-fill-element): ‘if’ without else -> ‘when’. (org-on-target-p): Remove ancient compatibility alias.
2018-05-10 01:02:35 +00:00
(lambda (a) (when (boundp a) (setq vars (cons (symbol-name a) vars)))))
(pcomplete-here vars)))
(defun pcomplete/org-mode/link ()
"Complete against defined #+LINK patterns."
(pcomplete-here
Many small code improvements * lisp/org-capture.el (org-capture-member): Make obsolete; the old definition was identical to ‘org-capture-get’ anyway. (org-capture-mode-map): Move the calls to ‘define-key’ up to where the variable is defined. (org-capture-mode-hook): Small docstring tweak. (org-capture-mode): Fix typo in mode lighter. (org-capture-set-target-location, org-capture-place-item): (org-capture-place-plain-text, org-capture-narrow): (org-capture-empty-lines-after): (org-capture-import-remember-templates): ‘if’ without else -> ‘when’ * lisp/org-colview.el (org-columns-edit-value): Change an error to a user-error. (org-columns-uncompile-format): Improve docstring. * lisp/org-compat.el (org-remove-from-invisibility-spec): Make obsolete, the underlying emacs function exists since 1997, commit 31aa282e. (org-in-invisibility-spec-p, org-count-lines): ‘if’ without else -> ‘when’. * lisp/org-element.el (org-element-swap-A-B): * lisp/org-entities.el (org-entities-create-table): * lisp/org-list.el (org-insert-item): * lisp/org-macs.el (org-with-point-at, org-base-buffer): (org-preserve-local-variables, org-overlay-display): (org-overlay-before-string): ‘if’ without else -> ‘when’. * lisp/org-eshell.el (org-eshell-open): Fix docstring typo. * lisp/org-pcomplete.el (pcomplete/org-mode/file-option/language): (pcomplete/org-mode/file-option/startup): (pcomplete/org-mode/file-option/options): (pcomplete/org-mode/file-option/infojs_opt): (pcomplete/org-mode/link, pcomplete/org-mode/tex): (pcomplete/org-mode/todo, pcomplete/org-mode/searchhead): (pcomplete/org-mode/tag, pcomplete/org-mode/prop): Avoid the formerly misspelled ‘pcomplete-uniqify-list’ function. It has a defalias in emacs >= 27; we add our own for older emacsen. (pcomplete/org-mode/file-option/bind): ‘if’ without else -> ‘when’. * lisp/org-protocol.el (org-protocol-capture): (org-protocol-convert-query-to-plist): ‘if’ without else -> ‘when’. (org-protocol-do-capture): Pacify byte compiler, simplify conditional logic. * lisp/org-table.el (org-table-create-with-table.el): Simplify conditional logic. (org-table-create, org-table-convert-region, org-table-next-field): (org-table-beginning-of-field, org-table-end-of-field): * lisp/org-w3m.el (org-w3m-copy-for-org-mode): ‘if’ without else -> ‘when’. * lisp/org.el (org-babel-do-load-languages, org-previous-link): (org-refile): Use ‘(foo ...)’ instead of ‘(funcall 'foo ...)’. (org-add-log-note): Convert a long cond into a cl-case. (org-priority): Improve docstring, show a deprecation warning if the ‘show’ argument is passed (which was previously silently ignored). Also, use ?\s instead of ?\ as a character literal for space. (org-fast-tag-insert): Fix docstring typo. (org-fill-element): ‘if’ without else -> ‘when’. (org-on-target-p): Remove ancient compatibility alias.
2018-05-10 01:02:35 +00:00
(pcomplete-uniquify-list
(copy-sequence
(mapcar (lambda (e) (concat (car e) ":"))
(append org-link-abbrev-alist-local
org-link-abbrev-alist))))))
(defun pcomplete/org-mode/tex ()
"Complete against TeX-style HTML entity names."
(require 'org-entities)
(while (pcomplete-here
(pcomplete-uniquify-list
(remove nil (mapcar #'car-safe org-entities)))
(substring pcomplete-stub 1))))
(defun pcomplete/org-mode/todo ()
"Complete against known TODO keywords."
Many small code improvements * lisp/org-capture.el (org-capture-member): Make obsolete; the old definition was identical to ‘org-capture-get’ anyway. (org-capture-mode-map): Move the calls to ‘define-key’ up to where the variable is defined. (org-capture-mode-hook): Small docstring tweak. (org-capture-mode): Fix typo in mode lighter. (org-capture-set-target-location, org-capture-place-item): (org-capture-place-plain-text, org-capture-narrow): (org-capture-empty-lines-after): (org-capture-import-remember-templates): ‘if’ without else -> ‘when’ * lisp/org-colview.el (org-columns-edit-value): Change an error to a user-error. (org-columns-uncompile-format): Improve docstring. * lisp/org-compat.el (org-remove-from-invisibility-spec): Make obsolete, the underlying emacs function exists since 1997, commit 31aa282e. (org-in-invisibility-spec-p, org-count-lines): ‘if’ without else -> ‘when’. * lisp/org-element.el (org-element-swap-A-B): * lisp/org-entities.el (org-entities-create-table): * lisp/org-list.el (org-insert-item): * lisp/org-macs.el (org-with-point-at, org-base-buffer): (org-preserve-local-variables, org-overlay-display): (org-overlay-before-string): ‘if’ without else -> ‘when’. * lisp/org-eshell.el (org-eshell-open): Fix docstring typo. * lisp/org-pcomplete.el (pcomplete/org-mode/file-option/language): (pcomplete/org-mode/file-option/startup): (pcomplete/org-mode/file-option/options): (pcomplete/org-mode/file-option/infojs_opt): (pcomplete/org-mode/link, pcomplete/org-mode/tex): (pcomplete/org-mode/todo, pcomplete/org-mode/searchhead): (pcomplete/org-mode/tag, pcomplete/org-mode/prop): Avoid the formerly misspelled ‘pcomplete-uniqify-list’ function. It has a defalias in emacs >= 27; we add our own for older emacsen. (pcomplete/org-mode/file-option/bind): ‘if’ without else -> ‘when’. * lisp/org-protocol.el (org-protocol-capture): (org-protocol-convert-query-to-plist): ‘if’ without else -> ‘when’. (org-protocol-do-capture): Pacify byte compiler, simplify conditional logic. * lisp/org-table.el (org-table-create-with-table.el): Simplify conditional logic. (org-table-create, org-table-convert-region, org-table-next-field): (org-table-beginning-of-field, org-table-end-of-field): * lisp/org-w3m.el (org-w3m-copy-for-org-mode): ‘if’ without else -> ‘when’. * lisp/org.el (org-babel-do-load-languages, org-previous-link): (org-refile): Use ‘(foo ...)’ instead of ‘(funcall 'foo ...)’. (org-add-log-note): Convert a long cond into a cl-case. (org-priority): Improve docstring, show a deprecation warning if the ‘show’ argument is passed (which was previously silently ignored). Also, use ?\s instead of ?\ as a character literal for space. (org-fast-tag-insert): Fix docstring typo. (org-fill-element): ‘if’ without else -> ‘when’. (org-on-target-p): Remove ancient compatibility alias.
2018-05-10 01:02:35 +00:00
(pcomplete-here (pcomplete-uniquify-list (copy-sequence org-todo-keywords-1))))
(defun pcomplete/org-mode/searchhead ()
"Complete against all headings.
This needs more work, to handle headings with lots of spaces in them."
(while (pcomplete-here
(save-excursion
(goto-char (point-min))
(let (tbl)
(while (re-search-forward org-outline-regexp nil t)
;; Remove the leading asterisk from
;; `org-link-heading-search-string' result.
(push (substring (org-link-heading-search-string) 1) tbl))
(pcomplete-uniquify-list tbl))))))
(defun pcomplete/org-mode/tag ()
"Complete a tag name. Omit tags already set."
(while (pcomplete-here
(mapcar (lambda (x) (concat x ":"))
Many small code improvements * lisp/org-capture.el (org-capture-member): Make obsolete; the old definition was identical to ‘org-capture-get’ anyway. (org-capture-mode-map): Move the calls to ‘define-key’ up to where the variable is defined. (org-capture-mode-hook): Small docstring tweak. (org-capture-mode): Fix typo in mode lighter. (org-capture-set-target-location, org-capture-place-item): (org-capture-place-plain-text, org-capture-narrow): (org-capture-empty-lines-after): (org-capture-import-remember-templates): ‘if’ without else -> ‘when’ * lisp/org-colview.el (org-columns-edit-value): Change an error to a user-error. (org-columns-uncompile-format): Improve docstring. * lisp/org-compat.el (org-remove-from-invisibility-spec): Make obsolete, the underlying emacs function exists since 1997, commit 31aa282e. (org-in-invisibility-spec-p, org-count-lines): ‘if’ without else -> ‘when’. * lisp/org-element.el (org-element-swap-A-B): * lisp/org-entities.el (org-entities-create-table): * lisp/org-list.el (org-insert-item): * lisp/org-macs.el (org-with-point-at, org-base-buffer): (org-preserve-local-variables, org-overlay-display): (org-overlay-before-string): ‘if’ without else -> ‘when’. * lisp/org-eshell.el (org-eshell-open): Fix docstring typo. * lisp/org-pcomplete.el (pcomplete/org-mode/file-option/language): (pcomplete/org-mode/file-option/startup): (pcomplete/org-mode/file-option/options): (pcomplete/org-mode/file-option/infojs_opt): (pcomplete/org-mode/link, pcomplete/org-mode/tex): (pcomplete/org-mode/todo, pcomplete/org-mode/searchhead): (pcomplete/org-mode/tag, pcomplete/org-mode/prop): Avoid the formerly misspelled ‘pcomplete-uniqify-list’ function. It has a defalias in emacs >= 27; we add our own for older emacsen. (pcomplete/org-mode/file-option/bind): ‘if’ without else -> ‘when’. * lisp/org-protocol.el (org-protocol-capture): (org-protocol-convert-query-to-plist): ‘if’ without else -> ‘when’. (org-protocol-do-capture): Pacify byte compiler, simplify conditional logic. * lisp/org-table.el (org-table-create-with-table.el): Simplify conditional logic. (org-table-create, org-table-convert-region, org-table-next-field): (org-table-beginning-of-field, org-table-end-of-field): * lisp/org-w3m.el (org-w3m-copy-for-org-mode): ‘if’ without else -> ‘when’. * lisp/org.el (org-babel-do-load-languages, org-previous-link): (org-refile): Use ‘(foo ...)’ instead of ‘(funcall 'foo ...)’. (org-add-log-note): Convert a long cond into a cl-case. (org-priority): Improve docstring, show a deprecation warning if the ‘show’ argument is passed (which was previously silently ignored). Also, use ?\s instead of ?\ as a character literal for space. (org-fast-tag-insert): Fix docstring typo. (org-fill-element): ‘if’ without else -> ‘when’. (org-on-target-p): Remove ancient compatibility alias.
2018-05-10 01:02:35 +00:00
(let ((lst (pcomplete-uniquify-list
(or (remq
nil
(mapcar (lambda (x) (org-string-nw-p (car x)))
org-current-tag-alist))
(mapcar #'car (org-get-buffer-tags))))))
(dolist (tag (org-get-tags nil t))
(setq lst (delete tag lst)))
lst))
(and (string-match ".*:" pcomplete-stub)
(substring pcomplete-stub (match-end 0)))
t)))
(defun pcomplete/org-mode/drawer ()
"Complete a drawer name, including \"PROPERTIES\"."
(pcomplete-here
(org-pcomplete-case-double
(mapcar (lambda (x) (concat x ":"))
(let ((names (list "PROPERTIES")))
(save-excursion
(goto-char (point-min))
(while (re-search-forward org-drawer-regexp nil t)
(let ((drawer (org-element-at-point)))
(when (org-element-type-p drawer '(drawer property-drawer))
(push (org-element-property :drawer-name drawer) names)
(goto-char (org-element-end drawer))))))
(pcomplete-uniquify-list names))))
(substring pcomplete-stub 1))) ;remove initial colon
(defun pcomplete/org-mode/prop ()
"Complete a property name. Omit properties already set."
(pcomplete-here
(org-pcomplete-case-double
(mapcar (lambda (x)
(concat x ": "))
(let ((lst (pcomplete-uniquify-list
(copy-sequence (org-buffer-property-keys nil t t)))))
(dolist (prop (org-entry-properties))
(setq lst (delete (car prop) lst)))
lst)))
(substring pcomplete-stub 1)))
(defun pcomplete/org-mode/block-option/src ()
2018-09-20 09:23:49 +00:00
"Complete the arguments of a source block.
Complete a language in the first field, the header arguments and
switches."
(pcomplete-here
(mapcar
(lambda(x) (symbol-name (nth 3 x)))
(cdr (car (cdr (memq :key-type (plist-get
(symbol-plist
'org-babel-load-languages)
'custom-type)))))))
(let* ((info (org-babel-get-src-block-info 'no-eval))
(lang (car info))
(lang-headers (intern (concat "org-babel-header-args:" lang)))
(headers (org-babel-combine-header-arg-lists
org-babel-common-header-args-w-values
(and (boundp lang-headers) (eval lang-headers t)))))
(while (pcomplete-here
(append (mapcar
(lambda (arg) (format ":%s" (symbol-name (car arg))))
headers)
'("-n" "-r" "-l"))))))
(defun pcomplete/org-mode/block-option/clocktable ()
"Complete keywords in a clocktable line."
(while (pcomplete-here '(":maxlevel" ":scope" ":lang"
":tstart" ":tend" ":block" ":step"
":stepskip0" ":fileskip0"
":emphasize" ":link" ":narrow" ":indent"
":hidefiles" ":tcolumns" ":level" ":compact"
":timestamp" ":formula" ":formatter"
":wstart" ":mstart"))))
2018-10-18 16:09:41 +00:00
;;; Finish up
(provide 'org-pcomplete)
;;; org-pcomplete.el ends here