 (defun danylo/julia-inside-docstring ()
   "Check if point is inside julia-mode function docstring."
   (let* ((ppss (save-excursion (syntax-ppss)))
-         (in-triple-quote-string (and (not (nth 4 ppss)) (nth 8 ppss))))
-    (if in-triple-quote-string
+         (in-string (nth 3 ppss))
+         (in-triple-quote (and in-string (not (eq in-string ?\")))))
+    (if in-triple-quote
         (progn
           (danylo/search-region-delims "\"\"\"" "\"\"\"")
           (if danylo/begin t nil))

    (unless (danylo/fill)
      (fill-paragraph))
    ))

(general-define-key
 "M-q" 'danylo/smart-fill)

           "# Returns\n"
           "- `bar`: description.")
   "\n\"\"\"" t))

(defun danylo/docstring-insert-style (left right &optional display)
  "Insert specified (e.gg, markdown) delimiters into a docstring."
  (let (orig-pos indent-string-prefix)
    (if (and transient-mark-mode mark-active)
        (let ((text (delete-and-extract-region
                     (region-beginning) (region-end))))
          (if display
              (progn
                (setq indent-string-prefix
                      (make-string (current-indentation) ?\s))
                (insert (format "%s\n%s" left indent-string-prefix))
                (insert text)
                (setq orig-pos (point))
                (insert (format "\n%s%s" indent-string-prefix right))
                (goto-char orig-pos))
            (progn
              (insert (format "%s%s" left text))
              (setq orig-pos (point))
              (insert right)
              (goto-char orig-pos))))
      (if display
          (progn
            (setq indent-string-prefix
                  (make-string (current-indentation) ?\s))
            (insert (format "%s\n%s" left indent-string-prefix))
            (setq orig-pos (point))
            (insert (format "\n%s%s" indent-string-prefix right))
            (goto-char orig-pos))
        (progn
          (insert (format "%s%s" left right))
          (backward-char (length right)))))))

(defalias 'danylo/docstring-insert-bold
  (lambda () (interactive) (danylo/docstring-insert-style "**" "**"))
  "Insert bold text delimiters.")

(defalias 'danylo/docstring-insert-italic
  (lambda () (interactive) (danylo/docstring-insert-style "*" "*"))
  "Insert italic text delimiters.")

(defalias 'danylo/docstring-insert-literal
  (lambda ()
    (interactive)
    (if current-prefix-arg
        (danylo/docstring-insert-style "```julia" "```" t)
      (danylo/docstring-insert-style "`" "`")))
  "Insert inline or display source code delimiters.")

(defalias 'danylo/docstring-insert-equation
  (lambda ()
    (interactive)
    (if current-prefix-arg
        (danylo/docstring-insert-style "```math" "```" t)
      (danylo/docstring-insert-style "``" "``")))
  "Insert inline or display math delimiters.")

;;; ..:: Lisp ::..

