 
 (setq-default fill-column danylo/fill-column)
 
+;;;; Filling special structures
+
+(defun danylo/search-region-delims (start-re &optional end-re)
+  "Return the start and end points of a region using regular
+expressions. If not inside the region, returns nil."
+  (unless end-re (setq end-re start-re))
+  (setq danylo/begin nil danylo/end nil)
+  (save-excursion
+    (let ((danylo/region-begin (re-search-backward start-re nil t 1))
+	  (danylo/region-end (re-search-forward end-re nil t 1)))
+      (when (and danylo/region-begin
+		 danylo/region-end
+		 (> danylo/region-end danylo/region-begin))
+	(setq danylo/begin danylo/region-begin)
+	(setq danylo/end danylo/region-end))
+      )))
+
+(defun danylo/org-inside-block ()
+  "Check if point is inside org-mode structure."
+  (danylo/search-region-delims "#\\+begin_export" "#\\+end_export")
+  (if danylo/begin t nil))
+
+(defun danylo/julia-inside-docstring ()
+  "Check if point is inside julia-mode function docstring."
+  (danylo/search-region-delims "\"\"\"")
+  (if danylo/begin t nil))
+
+(defun danylo/fill-region (delim-fun)
+  "Fill an Org-mode block structure. The DELIM-FUN specifies which
+function to use to get the region delimiters."
+  (interactive)
+  (save-excursion
+    (when (funcall delim-fun)
+      (let* ((region-start (progn (goto-char danylo/begin)
+				  (forward-line)
+				  (point)))
+	     (region-end (progn (goto-char danylo/end)
+				(forward-line 0)
+				(1- (point)))))
+	(pulse-momentary-highlight-region region-start region-end)
+	(fill-region region-start region-end)))))
+
+(defun danylo/fill (&optional justify region)
+  "Enable custom filling depending on mode."
+  (cond ((and (not (and transient-mark-mode mark-active))
+	      (derived-mode-p 'org-mode)
+	      (danylo/org-inside-block))
+	 (danylo/fill-region 'danylo/org-inside-block))
+	((and (not (and transient-mark-mode mark-active))
+	      (derived-mode-p 'julia-mode)
+	      (danylo/julia-inside-block))
+	 (danylo/fill-region 'danylo/julia-inside-block))))
+(advice-add 'fill-paragraph :before 'danylo/fill)
+;; (advice-remove 'fill-paragraph #'danylo/fill)
+
 ;;; ..:: Window management ::..
 
 ;;;; >> Movement across windows <<

return it, but do not print to buffer."
  (interactive)
  (let ((link (read-string "Reference: "))
	(desc (read-string "Description: "))
	(orig-pos (point))
	new-pos link-text)
    (setq link-text (format "[[%s][%s]]" link desc))
    (if noinsert
	link-text

			 (add-to-list 'electric-pair-text-pairs '(?` . ?`))
			 )))
  :bind (:map julia-mode-map
	      ("C-h ." . danylo/julia-help-at-point)))

(use-package lsp-julia
  ;; https://github.com/non-Jedi/lsp-julia
