回答:
URL解析が含まれる可能性があるため、これを例として取り上げますが、一般的な考え方は次のようになります。
(defun my/minify-urls (beg end)
(interactive
(if (region-active-p)
(list (region-beginning) (region-end))
(list (point-min) (point-max))))
(save-excursion
(goto-char beg)
(while (re-search-forward "<\\w+:\\/\\/\\(:?[^>\\/]+\\/\\)*\\([^>\\/]+\\)>" end t)
(message "matched")
(let* ((all (match-string 0))
(match (match-string 1))
(ibeg (- (point) (length all) -1))
(iend (- (point) (length match) -3)))
(make-text-button iend (1- (point))
'len (- iend ibeg)
'state nil
'action (lambda (button)
(let ((state (button-get button 'state))
(len (button-get button 'len))
(pos (button-start button)))
(add-text-properties
(- pos len) pos
(if state '(invisible t) '(invisible nil)))
(button-put button 'state (not state)))))
(add-text-properties ibeg iend '(invisible t))))))
RET URLで展開/縮小状態を切り替えます。
goto-address-mode
。貢献をご検討ください。