emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/objed 209f0a6 20/21: Add reformat op


From: Clemens Radermacher
Subject: [elpa] externals/objed 209f0a6 20/21: Add reformat op
Date: Sun, 17 Mar 2019 15:00:19 -0400 (EDT)

branch: externals/objed
commit 209f0a684f4bc930747e3199d4a67b93425de9e8
Author: Clemens Radermacher <address@hidden>
Commit: Clemens Radermacher <address@hidden>

    Add reformat op
---
 objed.el | 28 +++++++++++++++++++++++-----
 1 file changed, 23 insertions(+), 5 deletions(-)

diff --git a/objed.el b/objed.el
index d200a89..7dfd48c 100644
--- a/objed.el
+++ b/objed.el
@@ -23,8 +23,9 @@
 ;;; Commentary:
 ;;
 ;; A global minor-mode to navigate and edit text objects. Objed enables modal
-;; editing and composition of commands, too. It combines ideas of other Editors
-;; like Vim or Kakoune and tries to align them with regular Emacs conventions.
+;; editing and composition of commands, too. It combines ideas of other
+;; Editors like Vim or Kakoune and tries to align them with regular Emacs
+;; conventions.
 ;;
 ;; For more information also see:
 ;;
@@ -832,8 +833,9 @@ Other single character keys are bound to `objed-undefined'."
     (define-key map "c"
       ;; upcase, downcase, capitalize, reformat
       (objed-define-op nil objed-case-op))
-    ;; (define-key map "q" 'objed-reformat-object)
 
+    (define-key map "q"
+      (objed-define-op nil objed-reformat-op ignore))
     (define-key map "e" 'objed-eval)
     (define-key map "r" ctl-x-r-map)
     (define-key map "n" 'objed-narrow)
@@ -2676,6 +2678,22 @@ If REPLACE is non-nil replace the region with the 
result."
                 (insert str)))))))))
 
 
+;; TODO: toggle like fill/unfill
+(defun objed-reformat-op (beg end)
+  "Reformat object between BEG and END."
+  (interactive "r")
+  (cond ((memq objed--object (list 'paragraph 'sentence 'line 'textblock))
+         (fill-paragraph)
+         (objed--init objed--object))
+        ((memq objed--object (list 'sexp 'bracket))
+         (save-excursion
+           (goto-char beg)
+           (indent-pp-sexp))
+         (objed--init objed--object))
+        (t
+         (objed-indent beg end))))
+
+
 (defun objed-eval (&optional replace)
   "Eval objects.
 
@@ -2696,8 +2714,8 @@ If REPLACE is non-nil replace evaluated code with result."
 (defun objed-pipe-region (beg end cmd &optional variant)
   "Pipe region text between BEG and END through a shell CMD.
 
-VARIANT is either the char r or e to either replace the text with
-the result or to echo it."
+VARIANT is either the char r or e to either replace the text with the result
+or to echo it."
   (interactive (let ((variant (read-char-choice "Replace [r] Echo [e] "
                                                 (list ?r ?e)))
                      (cmd (read-shell-command "Shell command: ")))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]