Permalink
Browse files

lots of new helper functions

  • Loading branch information...
1 parent fc59599 commit d6c1526cbe41760114c80ae57b07f1ee0c3ff243 @tavisrudd committed Jun 10, 2010
Showing with 208 additions and 27 deletions.
  1. +2 −0 dss-clipboard-integration.el
  2. +77 −0 dss-codenav-helpers.el
  3. +11 −24 dss-completion.el
  4. +2 −0 dss-keybindings.el
  5. +103 −2 dss-python.el
  6. +11 −0 dss-whitespace-and-linelen.el
  7. +2 −1 init.el
View
2 dss-clipboard-integration.el
@@ -1,3 +1,5 @@
+(require 'browse-kill-ring)
+
(setq x-select-enable-clipboard t)
;; Ideas and code stolen from
View
77 dss-codenav-helpers.el
@@ -1,3 +1,80 @@
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+(defun dss/display-syntax (syntax-type)
+ (eq syntax-type (syntax-ppss-context (syntax-ppss))))
+
+(defun dss/in-syntax-p (syntax-type)
+ "This only answers if you're in a comment or string at the moment."
+ (eq syntax-type (syntax-ppss-context (syntax-ppss))))
+
+(defun dss/in-string-p ()
+ (dss/in-syntax-p 'string))
+
+(defun dss/in-comment-p ()
+ (dss/in-syntax-p 'comment))
+
+(defun dss/blank-line-p ()
+ "Return non-nil iff current line is blank."
+ (save-excursion
+ (beginning-of-line)
+ (looking-at "\\s-*$")))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+(defun dss/beginning-of-string ()
+ "Go to beginning of string around point.
+Do nothing if not in string."
+ ;; from loveshack's python-beginning-of-string
+ (interactive)
+ (let ((state (syntax-ppss)))
+ (when (eq 'string (syntax-ppss-context state))
+ (goto-char (nth 8 state)))))
+
+(defun dss/end-of-string ()
+ (interactive)
+ (if (dss/in-string-p)
+ (progn
+ (dss/beginning-of-string)
+ (forward-sexp))))
+
+(defun dss/mark-string ()
+ (interactive)
+ (if (dss/in-string-p)
+ (progn
+ (dss/beginning-of-string)
+ (mark-sexp))))
+
+(defun dss/forward-string (&optional backward)
+ (interactive)
+ (if (dss/in-string-p)
+ (dss/end-of-string))
+ (while (not (dss/in-string-p))
+ (if backward
+ (backward-char)
+ (forward-char))))
+
+(defun dss/backward-string ()
+ (interactive)
+ (if (dss/in-string-p)
+ (dss/beginning-of-string))
+ (dss/forward-string t)
+ (dss/beginning-of-string)
+ (forward-char))
+
+;@@TR: I should add some similar functions for working with comments etc.
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+(defun dss/electric-pair ()
+ "If at end of line, insert character pair without surrounding spaces.
+ Otherwise, just insert the typed character."
+ (interactive)
+ ;(if (eolp) (let (parens-require-spaces) (insert-pair))
+ ; (self-insert-command 1)))
+ (if (or (dss/in-string-p)
+ (dss/in-comment-p))
+ (self-insert-command 1)
+ (let (parens-require-spaces)
+ (insert-pair))))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'imenu)
(defun ido-imenu ()
"Update the imenu index and then use ido to select a symbol to navigate to.
View
35 dss-completion.el
@@ -29,7 +29,6 @@
)
-
;;; http://stackoverflow.com/questions/905338/can-i-use-ido-completing-read-instead-of-completing-read-everywhere
(defvar ido-enable-replace-completing-read t
"If t, use ido-completing-read instead of completing-read if possible.
@@ -56,6 +55,16 @@ advice like this:
nil require-match initial-input hist def))
ad-do-it))) " ")
+;; (defadvice where-is
+;; (around where-is-completing-read-only activate)
+;; (let (ido-enable-replace-completing-read) ad-do-it))
+
+(defun dss/where-is ()
+ "wrapper around where-is that doesn't use ido for completion"
+ (interactive)
+ (let (ido-enable-replace-completing-read)
+ (call-interactively 'where-is)))
+
;; also see dss/load-rope-completion in dss-python.el
@@ -211,30 +220,8 @@ in the current *Python* session."
(requires . 0)
(symbol . "f")))
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-(defun dss/in-string-p ()
- (eq 'string (syntax-ppss-context (syntax-ppss))))
-
-(defun dss/beginning-of-string ()
- "Go to beginning of string around point.
-Do nothing if not in string."
- ;; from loveshack's python-beginning-of-string
- (interactive)
- (let ((state (syntax-ppss)))
- (when (eq 'string (syntax-ppss-context state))
- (goto-char (nth 8 state)))))
-
-(defun dss/electric-pair ()
- "If at end of line, insert character pair without surrounding spaces.
- Otherwise, just insert the typed character."
- (interactive)
- ;(if (eolp) (let (parens-require-spaces) (insert-pair))
- ; (self-insert-command 1)))
- (if (dss/in-string-p)
- (self-insert-command 1)
- (let (parens-require-spaces)
- (insert-pair))))
+(require 'dss-codenav-helpers)
(defun dss/ac-electric-pair ()
(interactive)
(ac-complete)
View
2 dss-keybindings.el
@@ -111,6 +111,8 @@
(define-key f2-map "=" 'dvc-status)
(define-key f2-map "-" 'dvc-diff)
+(define-key f2-map "r" 'recursive-edit)
+
;; f4-map
View
105 dss-python.el
@@ -38,7 +38,42 @@
(insert "pylint: disable-msg="))
(insert msgid)))
-(defun dss/insert-docstring ()
+(defun dss/out-sexp (&optional level forward syntax)
+ "Skip out of any nested brackets.
+ Skip forward if FORWARD is non-nil, else backward.
+ If SYNTAX is non-nil it is the state returned by `syntax-ppss' at point.
+ Return non-nil if and only if skipping was done."
+ (interactive)
+ (if (dss/in-string-p)
+ (dss/beginning-of-string))
+ (progn
+ (let* ((depth (syntax-ppss-depth (or syntax (syntax-ppss))))
+ (level (or level depth))
+ (forward (if forward -1 1)))
+ (unless (zerop depth)
+ (if (> depth 0)
+ ;; Skip forward out of nested brackets.
+ (condition-case () ; beware invalid syntax
+ (progn (backward-up-list (* forward level)) t)
+ (error nil))
+ ;; Invalid syntax (too many closed brackets).
+ ;; Skip out of as many as possible.
+ (let (done)
+ (while (condition-case ()
+ (progn (backward-up-list forward)
+ (setq done t))
+ (error nil)))
+ done))))))
+
+(defun dss/out-one-sexp (&optional forward)
+ (interactive)
+ (dss/out-sexp 1 forward))
+
+(defun dss/out-one-sexp-forward ()
+ (interactive)
+ (dss/out-sexp 1 1))
+
+(defun dss/py-insert-docstring ()
(interactive)
(if (not (save-excursion
(forward-line 1)
@@ -56,11 +91,77 @@
(forward-line 1)
(end-of-line)))
-(defun dss/insert-triple-quote ()
+(defun dss/py-insert-triple-quote ()
(interactive)
(insert "\"\"\"")
(save-excursion (insert " \"\"\"")))
+(defun dss/py-fix-indent (top bottom)
+ (interactive "r")
+ (apply-macro-to-region-lines top bottom (kbd "TAB")))
+
+(defun dss/py-fix-last-utterance ()
+ "Downcase the previous word and remove any leading whitespace.
+This is useful with Dragon NaturallySpeaking."
+ (interactive)
+ (save-excursion
+ (backward-word)
+ (set-mark (point))
+ (call-interactively 'py-forward-into-nomenclature)
+ (call-interactively 'downcase-region)
+ (setq mark-active nil)
+ (backward-word)
+ (delete-horizontal-space t)))
+
+(defun dss/py-dot-dictate (words)
+ (interactive "s")
+ (progn
+ (if (looking-at-p "\\.")
+ (forward-char))
+ (delete-horizontal-space t)
+ (if (save-excursion
+ (backward-char)
+ (not (looking-at-p "\\.")))
+ (insert "."))
+ (insert (mapconcat 'identity (split-string words) "_"))
+ (dss/py-fix-last-utterance)
+ (delete-horizontal-space t)))
+
+(defun dss/py-decorate-function (&optional decorator-name)
+ (interactive)
+ (if (not (looking-at "@"))
+ (progn
+ (py-beginning-of-def-or-class)
+ (while (not (save-excursion
+ (forward-line -2)
+ (beginning-of-line-text)
+ (looking-at-p "$")))
+ (save-excursion
+ (forward-line -1)
+ (end-of-line)
+ (open-line 1)))
+ (forward-line -1)
+ (py-indent-line)
+ (beginning-of-line-text)
+ (if (not (looking-at "@"))
+ (progn
+ (insert "@")
+ (if decorator-name
+ (insert decorator-name)))))))
+
+(defun dss/py-make-classmethod ()
+ (interactive)
+ (dss/py-decorate-function "classmethod"))
+
+(defun dss/py-comment-line-p ()
+ "Return non-nil iff current line has only a comment.
+This is python-comment-line-p from Dave Love's python.el"
+ (save-excursion
+ (end-of-line)
+ (when (eq 'comment (syntax-ppss-context (syntax-ppss)))
+ (back-to-indentation)
+ (looking-at (rx (or (syntax comment-start) line-end))))))
+
;; setup pymacs
(autoload 'pymacs-apply "pymacs")
(autoload 'pymacs-call "pymacs")
View
11 dss-whitespace-and-linelen.el
@@ -16,6 +16,17 @@
(show-ws-highlight-tabs)
(hl-line-mode 1))
+(defun dss/del-last-space (&optional replacement)
+ (interactive)
+ (let ((replacement (or replacement "")))
+ (save-excursion
+ (search-backward-regexp "\\([^ ]\\)\\( +\\)")
+ (replace-match replacement nil nil nil 2))))
+
+(defun dss/less-space ()
+ (interactive)
+ (dss/del-last-space " "))
+
(defun dss/whitespace-cleanup ()
"Trim all trailing whitespace in the current buffer, and untabify."
(interactive)
View
3 init.el
@@ -12,8 +12,10 @@
(require 'dss-elpa-support)
;; global stuff
+(require 'dss-basic-editing)
(require 'dss-whitespace-and-linelen)
(require 'dss-buffer-and-window-handling)
+(require 'dss-codenav-helpers)
(require 'dss-completion)
(require 'dss-search-occur-etc)
(require 'dss-bookmarks-registers)
@@ -35,7 +37,6 @@
(require 'dss-clojure)
;; other support funcs and minor modes
-(require 'dss-codenav-helpers)
(require 'dss-keybindings)
(require 'dss-colorthemes)
(require 'dss-browser-integration)

0 comments on commit d6c1526

Please sign in to comment.