Coder Social home page Coder Social logo

company-org-block's Introduction

πŸ‘‰ Support my work via GitHub Sponsors

Hi, I’m Álvaro πŸ‘‹

company-org-block's People

Contributors

jcs090218 avatar mohkale avatar takaxp avatar xenodium avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

company-org-block's Issues

Better handling of src blocks

Sometimes the language I want to create a code block isn't setup by default in org. For example SQL code blocks. In this case I enter <src to create a src code block but company-org-block takes me to the body of the block making me have to navigate back to the definition and then attach the language I want.

It would be nice if:

  1. company-org-block started a completing-read session in this case to ask the user the type of code block their creating.
  2. Remembered this decision so later attempts to create the same code block aren't as indirect.

Thoughts?

Gracefully handle lack of special environment to edit

Some code blocks (such as quote) give an error when you try to edit them, however with company-org-block-edit-style set to auto, company-org-block will just let the error propagate.

This diff should gracefully handle it.

--- /home/mohkale/.config/dotfiles/prog/editors/emacs/lisp/straight/repos/company-org-block/company-org-block.el
+++ #<buffer company-org-block.el>
@@ -110,11 +110,16 @@
   (insert (make-string org-edit-src-content-indentation ?\s))
   (save-excursion
     (insert (format "\n#+end_%s" end)))
-  (cond ((eq company-org-block-edit-style 'auto)
-         (org-edit-special))
-        ((and (eq company-org-block-edit-style 'prompt)
-              (yes-or-no-p "Edit now?"))
-         (org-edit-special))))
+  (condition-case err
+      (cond ((eq company-org-block-edit-style 'auto)
+             (org-edit-special))
+            ((and (eq company-org-block-edit-style 'prompt)
+                  (yes-or-no-p "Edit now?"))
+             (org-edit-special)))
+    (user-error
+     (unless (string-equal "No special environment to edit here"
+                           (error-message-string err))
+       (signal (car err) (cdr err))))))
 
 (defun company-org-block--grab-symbol-cons ()
   "Return cons with symbol and t whenever prefix of < is found.

Can't automatically trigger completion

Great package, but I'm having trouble automatically triggering completion. I've set it up using the use-package instructions you provided, but nothing pops up when I insert <. But completion does pop up when I run company-org-block.

Errors after "<" invocation.

Running into below errors from opening "<" for org block completion.

Debugger entered--Lisp error: (wrong-type-argument stringp ("#+BEGIN_SRC lisp\n\n#+END_SRC")) string-lessp(("#+BEGIN_SRC lisp\n\n#+END_SRC") "lisp") sort(("lisp") string-lessp) #f(compiled-function (pred list) #<bytecode 0x1022ee5>)(string-lessp ("lisp" ("#+BEGIN_SRC lisp\n\n#+END_SRC") ("#+BEGIN_SRC ?\n\n#+END_SRC") ("#+BEGIN_EXAMPLE\n?\n#+END_EXAMPLE") ("#+BEGIN_QUOTE\n?\n#+END_QUOTE") ("#+BEGIN_VERSE\n?\n#+END_VERSE") ("#+BEGIN_VERBATIM\n?\n#+END_VERBATIM") ("#+BEGIN_CENTER\n?\n#+END_CENTER") ("#+BEGIN_COMMENT\n?\n#+END_COMMENT") ("#+BEGIN_EXPORT latex\n?\n#+END_EXPORT") ("#+LaTeX: ") ("#+BEGIN_EXPORT html\n?\n#+END_EXPORT") ("#+HTML: ") ("#+BEGIN_EXPORT ascii\n?\n#+END_EXPORT") ("#+ASCII: ") ("#+INDEX: ?") ("#+INCLUDE: %file ?") "lisp" "el" "el")) apply(#f(compiled-function (pred list) #<bytecode 0x1022ee5>) string-lessp ("lisp" ("#+BEGIN_SRC lisp\n\n#+END_SRC") ("#+BEGIN_SRC ?\n\n#+END_SRC") ("#+BEGIN_EXAMPLE\n?\n#+END_EXAMPLE") ("#+BEGIN_QUOTE\n?\n#+END_QUOTE") ("#+BEGIN_VERSE\n?\n#+END_VERSE") ("#+BEGIN_VERBATIM\n?\n#+END_VERBATIM") ("#+BEGIN_CENTER\n?\n#+END_CENTER") ("#+BEGIN_COMMENT\n?\n#+END_COMMENT") ("#+BEGIN_EXPORT latex\n?\n#+END_EXPORT") ("#+LaTeX: ") ("#+BEGIN_EXPORT html\n?\n#+END_EXPORT") ("#+HTML: ") ("#+BEGIN_EXPORT ascii\n?\n#+END_EXPORT") ("#+ASCII: ") ("#+INDEX: ?") ("#+INCLUDE: %file ?") "lisp" "el" "el") nil) seq-sort(string-lessp ("lisp" ("#+BEGIN_SRC lisp\n\n#+END_SRC") ("#+BEGIN_SRC ?\n\n#+END_SRC") ("#+BEGIN_EXAMPLE\n?\n#+END_EXAMPLE") ("#+BEGIN_QUOTE\n?\n#+END_QUOTE") ("#+BEGIN_VERSE\n?\n#+END_VERSE") ("#+BEGIN_VERBATIM\n?\n#+END_VERBATIM") ("#+BEGIN_CENTER\n?\n#+END_CENTER") ("#+BEGIN_COMMENT\n?\n#+END_COMMENT") ("#+BEGIN_EXPORT latex\n?\n#+END_EXPORT") ("#+LaTeX: ") ("#+BEGIN_EXPORT html\n?\n#+END_EXPORT") ("#+HTML: ") ("#+BEGIN_EXPORT ascii\n?\n#+END_EXPORT") ("#+ASCII: ") ("#+INDEX: ?") ("#+INCLUDE: %file ?") "lisp" "el" "el")) company-org-block--candidates("") company-org-block(candidates "") apply(company-org-block (candidates "")) company-call-backend-raw(candidates "") company--fetch-candidates("") company-calculate-candidates("") company--begin-new() company--perform() company-auto-begin() company-idle-begin(#<buffer configuration.org> #<window 3 on configuration.org> 1578 11869) apply(company-idle-begin (#<buffer configuration.org> #<window 3 on configuration.org> 1578 11869)) timer-event-handler([t 24766 31847 402309 nil company-idle-begin (#<buffer configuration.org> #<window 3 on configuration.org> 1578 11869) nil 455000])

Here is my company-mode configuration.

(use-package company
   :ensure t
   :init (add-hook 'after-init-hook 'global-company-mode))

 (setq company-idle-delay 0)
 (setq company-minimum-prefix-length 3)
 (setq company-selection-wrap-around t)
 (company-tng-configure-default)

 (use-package company-org-block
   :ensure t
   :custom
   (company-org-block-edit-style 'prompt)
   :hook ((org-mode . (lambda ()
		    (setq-local company-backends '(company-org-block))
		    (company-mode +1)))))

Support leading white-space with org-adapt-indentation

Hi, love the package.

I agree you'd probably only ever want org-block completions when at the beginning of a line but for those of us that have org-adapt-indentation set to t, this package won't offer to complete any lines that're in a sub-heading because the lines are indented to match the heading level. I'd suggest allowing company-org-block-complete-at-bol to disregard leading whitespace.

This diff fixes the issue for me:

--- /home/mohkale/.config/dotfiles/prog/editors/emacs/lisp/straight/repos/company-org-block/company-org-block.el
+++ #<buffer company-org-block.el>
@@ -106,10 +106,12 @@
 #+begin_BEGIN
   |
 #+end_END"
+  (org-indent-line)
   (insert (format "#+begin_%s\n" begin))
   (insert (make-string org-edit-src-content-indentation ?\s))
   (save-excursion
-    (insert (format "\n#+end_%s" end)))
+    (insert (format "\n#+end_%s" end))
+    (org-indent-line))
   (cond ((eq company-org-block-edit-style 'auto)
          (org-edit-special))
         ((and (eq company-org-block-edit-style 'prompt)
@@ -120,7 +122,7 @@
   "Return cons with symbol and t whenever prefix of < is found.
 For example: \"<e\" -> (\"e\" . t)"
   (when (looking-back (if company-org-block-complete-at-bol
-                          (concat "^" company-org-block--regexp)
+                          (concat "^[[:space:]]*" company-org-block--regexp)
                         company-org-block--regexp)
                       (line-beginning-position))
     (cons (match-string-no-properties 1) t)))

Also I'd like to ask whether there's a reason behind the lack of a trailing newline on the end_src? In my emacs not having one leads to the font-lock at that point getting cut off.
Screenshot_20210606_180433

Trigger key `<` and `electric-pair-mode`

This looks like a very useful package, I just have one little nit: in an Org buffer, pressing < inserts an additional >, because I have electric-pair-mode turned on. Completion and editing of the source block still work perfectly, but the < character is left in the buffer, which means I need to delete it manually.

Is there something that could be done about this? I know nothing about the internals of company-mode or of electric-pair-mode, so I don't know if there is a way to inhibit the insertion of the closing >. Perhaps you could check for > following < and delete it if electric-pair-mode is turned on? Or perhaps less brittle, make the trigger key customisable?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.