;; .ooSSSSSSooo. ;; .uSXXXXXXXXXXXXXXXSu. ;; oXXXXXXXXXXXXXXXXXXXXXXXo ;; sXXXXXXXXXXXXXXXXXXXXXXXXXXXs ;; sXXXXXXXXXXXXXXXXXXXXXXXXXXXXXs ;; oXXXXXXXXXXXXXX` `XXXXXXXXXXXXXo ;; oXXXXXXXXXXXXX XXXXXXXXXXXXo ;; XXXXXXXXXXXXX XXXXXXXXXXXX ;; oXXXXXXXXXXXXX XXXXXXXXXXXXo ;; XXXXXXXXXXXXXX XXXXXXXXXXXXX ;; XXXXXXXXXXXXXXX XXXXXXXXXXXXXX ;; oXXXXXXXXXXXXXXX.. ..XXXXXXXXXXXXXXo ;; XXXXXXXXXXXXXXSSXXXXSSXXXXXXXXXXXXX ;; oXXXXXXXXXXXXXSSXXXXSSXXXXXXXXXXXXo ;; oXXXXXXXXXXXXSSXXXXSSXXXXXXXXXXXo ;; sXXXXXXXXXXXSSXXXXSSXXXXXXXXXXs ;; sXXXXXXXXXXSSXXXXSSXXXXXXXXXs ;; oXXXXXXXXSSXXXXSSXXXXXXXo ;; "uSXXXXSSXXXXSSXXXXSu" ;; ""SSSSSSSSS"" (require 'org) (defun orb (node) (list node (org-element-begin node) (org-element-end node))) (cl-defgeneric clean-content (orb type)) (cl-defmethod clean-content :after (orb type) (cl-rest orb)) (cl-defmethod clean-content (orb type) (declare (ignore type)) (cl-destructuring-bind (_ beg end) orb (string-clean-whitespace (buffer-substring-no-properties beg end)))) (cl-defmethod clean-content (orb (type (eql 'plain-list))) (declare (ignore type)) (cl-destructuring-bind (_ beg end) orb (string-clean-whitespace (buffer-substring-no-properties (+ beg 2) end)))) (cl-defmethod clean-content (orb (type (eql 'src-block))) (declare (ignore type)) (cl-destructuring-bind (_ beg end) orb (buffer-substring-no-properties (save-excursion (goto-char beg) (forward-line) (point)) (save-excursion (goto-char end) (re-search-backward "#\\+end_src" 79 t) (backward-char) (point))))) (defun find-around-for-org () (with-current-buffer (current-buffer) (let ((node (org-element-at-point))) (clean-content (orb node) (car node))))) (defun fafo () (interactive) (if (region-active-p) (call-interactively #'kill-ring-save) (let ((text (find-around-for-org))) (with-temp-buffer (insert text) (kill-region (point-min) (point-max))) (message "✔ %d" (length text))))) (define-key org-mode-map (kbd "M-w") #'fafo)