Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 52 additions & 4 deletions emr-c.el
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,52 @@ project, return all header files in the current directory."
(t nil)))

(defun emr-cc-format-region (start end)
"Format region (START/END) using clang."
"Format region (START/END) with clang-format."
(interactive "rp")
(clang-format-region start end (emr-cc-get-style)))

(defun emr-cc-format-buffer ()
"Format region (START/END) using clang."
"Format region (START/END) with clang-format."
(interactive)
(clang-format-buffer (emr-cc-get-style)))

(defalias 'emr-cc-tidy-includes 'emr-c-tidy-includes)

(defvar emr-cc-surround-var-hist nil
"A collection of variables used by if-defs..")

(defun emr-cc-surround-if-end (start end)
"Surround region between START & END with if-def."
(interactive "rp")
(let ((var (completing-read "Variable Name: " emr-cc-surround-var-hist
nil nil nil 'emr-cc-surround-var-hist)))
(kill-region start end)
(let ((s (point))
pos e)
(insert (format "#ifdef %s\n" var))
(yank)
(insert (format "\n#endif /*%s*/" var))
(setq pos (point))
(setq e (point))
(goto-char pos)
(emr-cc-format-region s e))))

(defun emr-cpp-try-catch (start end)
"Surround region between START & END with try-catch."
(interactive "rp")
(kill-region start end)
(let ((s (point))
pos end)
(insert "try {\n")
(yank)
(insert
"}\ncatch (exception& e) {\n")
(setq pos (point))
(insert "throw ;\n}\n")
(setq e (point))
(goto-char pos)
(emr-cc-format-region s e)))

; ------------------

;;; EMR Declarations
Expand All @@ -197,20 +232,33 @@ project, return all header files in the current directory."
(emr-c:looking-at-include?)))

(emr-declare-command 'emr-cc-format-region
:title "Format region"
:title "format region"
:description "with clang"
:modes '(c-mode c++-mode)
:predicate (lambda ()
(and mark-active (not (equal (mark) (point)))
(executable-find "clang-format"))))
(emr-declare-command 'emr-cc-format-buffer
:title "Format Buffer"
:title "format buffer"
:description "with clang"
:modes '(c-mode c++-mode)
:predicate (lambda ()
(and (not mark-active)
(executable-find "clang-format"))))

(emr-declare-command 'emr-cc-surround-if-end
:title "surround"
:description "with if-endif"
:modes '(c++-mode c-mode)
:predicate (lambda ()
(and mark-active (not (equal (mark) (point))))))

(emr-declare-command 'emr-cpp-try-catch
:title "surround"
:description "with try-catch"
:modes '(c++-mode)
:predicate (lambda ()
(and mark-active (not (equal (mark) (point))))))

; ------------------

Expand Down
27 changes: 2 additions & 25 deletions emr-iedit.el
Original file line number Diff line number Diff line change
Expand Up @@ -65,41 +65,18 @@
(setq iedit-initial-string-local occurrence)
(iedit-start (iedit-regexp-quote occurrence) beg end)))

(defun emr-iedit-in-region (arg)
"Rename variable in this function"
(interactive "P")
(iedit-barf-if-lib-active)
(let (occurrence
complete-symbol
(beg (region-beginning))
(end (region-end)))
(setq occurrence (buffer-substring-no-properties
(mark) (point)))
(setq iedit-only-complete-symbol-local complete-symbol)
(setq mark-active nil)
(run-hooks 'deactivate-mark-hook)
(setq iedit-initial-string-local occurrence)
(iedit-start (iedit-regexp-quote occurrence) beg end)))


(emr-declare-command 'emr-iedit-in-function
:title "Rename (in function)"
:title "rename (in function)"
:description "in function"
:modes '(prog-mode)
:predicate (lambda ()
(and (not (iedit-region-active))
(emr-iedit:looking-at-iterator?)
(which-function))))

(emr-declare-command 'emr-iedit-in-region
:title "Rename (in region)"
:description "in region"
:modes '(prog-mode)
:predicate (lambda ()
(iedit-region-active)))

(emr-declare-command 'emr-iedit-global
:title "Rename"
:title "rename"
:description "globally"
:modes '(prog-mode)
:predicate (lambda ()
Expand Down