Permalink
Browse files

Add rename current buffer file function

  • Loading branch information...
1 parent f3b1cde commit 4d1ae018aad467eab3996e11e0460595e9f97e35 @julienXX committed Dec 29, 2012
Showing with 47 additions and 192 deletions.
  1. +1 −0 .gitignore
  2. +0 −16 .places
  3. +19 −7 functions.el
  4. +0 −144 functions.el.orig
  5. +27 −25 mappings.el
View
@@ -6,3 +6,4 @@ ac-comphist.dat
eshell
url
var
+.places
View
@@ -1,16 +0,0 @@
-;;; -*- coding: utf-8 -*-
-(("/Users/julien/.emacs.d/elpa/archives/ELPA/archive-contents" . 11669)
- ("/Users/julien/.emacs.d/elpa/archives/MELPA/archive-contents" . 73607)
- ("/Users/julien/.emacs.d/elpa/archives/gnu/archive-contents" . 4092)
- ("/Users/julien/.emacs.d/elpa/archives/marmalade/archive-contents" . 56233)
- ("/Users/julien/.emacs.d/elpa/clojure-mode-20121228.2134/clojure-mode-autoloads.el" . 1101)
- ("/Users/julien/.emacs.d/elpa/ess-20121228.1108/ess-autoloads.el" . 2148)
- ("/Users/julien/.emacs.d/elpa/haml-mode-20121228.2319/haml-mode-autoloads.el" . 471)
- ("/Users/julien/.emacs.d/elpa/js2-mode-20121225.323/js2-mode-autoloads.el" . 706)
- ("/Users/julien/.emacs.d/elpa/slime-20121227.2022/slime-autoloads.el" . 1359)
- ("/Users/julien/.emacs.d/elpa/solarized-theme-20121228.1654/solarized-theme-autoloads.el" . 551)
- ("/Users/julien/.emacs.d/elpa/yasnippet-20121225.430/yasnippet-autoloads.el" . 1498)
- ("/Users/julien/.emacs.d/functions.el" . 1237)
- ("/Users/julien/.emacs.d/init.el" . 1608)
- ("/Users/julien/.emacs.d/mappings.el" . 1422)
- ("/Users/julien/.emacs.d/packages.el" . 3893))
View
@@ -40,10 +40,8 @@
;; Behave like vi's o command
(defun open-line-below ()
(interactive)
- (if (eolp)
- (newline)
- (end-of-line)
- (newline))
+ (end-of-line)
+ (newline)
(indent-for-tab-command))
(defun open-line-above ()
@@ -53,9 +51,6 @@
(forward-line -1)
(indent-for-tab-command))
-(global-set-key (kbd "<C-return>") 'open-line-below)
-(global-set-key (kbd "<C-S-return>") 'open-line-above)
-
;; custom goto-line
;; turn line numbers off by default
(global-linum-mode -1)
@@ -139,3 +134,20 @@ Ignores CHAR at point."
(forward-line)
(transpose-lines -1))
(move-to-column col)))
+
+(defun rename-current-buffer-file ()
+ "Renames current buffer and file it is visiting."
+ (interactive)
+ (let ((name (buffer-name))
+ (filename (buffer-file-name)))
+ (if (not (and filename (file-exists-p filename)))
+ (error "Buffer '%s' is not visiting a file!" name)
+ (let ((new-name (read-file-name "New name: " filename)))
+ (if (get-buffer new-name)
+ (error "A buffer named '%s' already exists!" new-name)
+ (rename-file filename new-name 1)
+ (rename-buffer new-name)
+ (set-visited-file-name new-name)
+ (set-buffer-modified-p nil)
+ (message "File '%s' successfully renamed to '%s'"
+ name (file-name-nondirectory new-name)))))))
View
@@ -1,144 +0,0 @@
-(defun switch-to-previous-buffer ()
- (interactive)
- (switch-to-buffer (other-buffer (current-buffer) 1)))
-
-(defun duplicate-line (arg)
- "Duplicate current line, leaving point in lower line."
- (interactive "*p")
-
- ;; save the point for undo
- (setq buffer-undo-list (cons (point) buffer-undo-list))
-
- ;; local variables for start and end of line
- (let ((bol (save-excursion (beginning-of-line) (point)))
- eol)
- (save-excursion
-
- ;; don't use forward-line for this, because you would have
- ;; to check whether you are at the end of the buffer
- (end-of-line)
- (setq eol (point))
-
- ;; store the line and disable the recording of undo information
- (let ((line (buffer-substring bol eol))
- (buffer-undo-list t)
- (count arg))
- ;; insert the line arg times
- (while (> count 0)
- (newline) ;; because there is no newline in 'line'
- (insert line)
- (setq count (1- count)))
- )
-
- ;; create the undo information
- (setq buffer-undo-list (cons (cons eol (point)) buffer-undo-list)))
- ) ; end-of-let
-
- ;; put the point in the lowest line and return
- (next-line arg))
-
-;; Behave like vi's o command
-(defun open-line-below ()
- (interactive)
- (if (eolp)
- (newline)
- (end-of-line)
- (newline))
- (indent-for-tab-command))
-
-(defun open-line-above ()
- (interactive)
- (beginning-of-line)
- (newline)
- (forward-line -1)
- (indent-for-tab-command))
-
-(global-set-key (kbd "<C-return>") 'open-line-below)
-(global-set-key (kbd "<C-S-return>") 'open-line-above)
-
-;; custom goto-line
-;; turn line numbers off by default
-(global-linum-mode -1)
-
-(defun goto-line-with-feedback (&optional line)
- "Show line numbers temporarily, while prompting for the line number input"
- (interactive "P")
- (if line
- (goto-line line)
- (unwind-protect
- (progn
- (linum-mode 1)
- (goto-line (read-number "Goto line: ")))
- (linum-mode -1))))
-
-;; Toggle between split windows and a single window
-(defun toggle-windows-split()
- "Switch back and forth between one window and whatever split of windows we might have in the frame. The idea is to maximize the current buffer, while being able to go back to the previous split of windows in the frame simply by calling this command again."
- (interactive)
- (if (not (window-minibuffer-p (selected-window)))
- (progn
- (if (< 1 (count-windows))
- (progn
- (window-configuration-to-register ?u)
- (delete-other-windows))
- (jump-to-register ?u))))
- (my-iswitchb-close))
-
-(defun zap-up-to-char (arg char)
- "Kill up to, but not including ARGth occurrence of CHAR.
-Case is ignored if `case-fold-search' is non-nil in the current buffer.
-Goes backward if ARG is negative; error if CHAR not found.
-Ignores CHAR at point."
- (interactive "p\ncZap up to char: ")
- (let ((direction (if (>= arg 0) 1 -1)))
- (kill-region (point)
- (progn
- (forward-char direction)
- (unwind-protect
- (search-forward (char-to-string char) nil nil arg)
- (backward-char direction))
- (point)))))
-
-(defun ruby-open-spec-other-buffer ()
- (interactive)
- (when (featurep 'rspec-mode)
- (let ((source-buffer (current-buffer))
- (other-buffer (progn
- (rspec-toggle-spec-and-target)
- (current-buffer))))
- (switch-to-buffer source-buffer)
- (pop-to-buffer other-buffer))))
-
-(defun revert-all-buffers ()
- "Refreshes all open buffers from their respective files."
- (interactive)
- (dolist (buf (buffer-list))
- (with-current-buffer buf
- (when (and (buffer-file-name) (not (buffer-modified-p)))
- (revert-buffer t t t) )))
- (message "Refreshed open files.") )
-
-(defun jb-ac-tab-noconflict ()
- (let ((command (key-binding [tab]))) ; remember command
- (local-unset-key [tab]) ; unset from (kbd "<tab>")
- (local-set-key (kbd "TAB") command))) ; bind to (kbd "TAB")
-<<<<<<< HEAD
-
-(defun move-line-down ()
- (interactive)
- (let ((col (current-column)))
- (save-excursion
- (forward-line)
- (transpose-lines 1))
- (forward-line)
- (move-to-column col)))
-
-(defun move-line-up ()
- (interactive)
- (let ((col (current-column)))
- (save-excursion
- (forward-line)
- (transpose-lines -1))
- (move-to-column col)))
-=======
->>>>>>> e3428879bd7f0789ccb981ee2516e757607553c6
View
@@ -1,25 +1,27 @@
-(global-set-key (kbd "C-c s") 'shell)
-(global-set-key (kbd "C-x C-v") 'ido-find-file-other-window)
-(global-set-key (kbd "C-c c") 'switch-to-previous-buffer)
-(global-set-key (kbd "M-t") 'textmate-goto-file)
-(global-set-key (kbd "M-T") 'textmate-goto-symbol)
-(global-set-key (kbd "C-c d") 'duplicate-line)
-(global-set-key (kbd "M-]") 'textmate-shift-right)
-(global-set-key (kbd "M-[") 'textmate-shift-left)
-(global-set-key (kbd "M-/") 'comment-or-uncomment-region)
-(global-set-key (kbd "C-x à") 'delete-window)
-(global-set-key (kbd "C-x &") 'delete-other-windows)
-(global-set-key (kbd "C-x é") 'split-window-below)
-(global-set-key (kbd "C-x \"") 'split-window-right)
-(global-set-key (kbd "M-L") 'textmate-select-line)
-(global-set-key (kbd "C-c o") 'vi-open-line-above)
-(global-set-key (kbd "C-o") 'vi-open-line-below)
-(global-set-key (kbd "C-c g") 'magit-status)
-(global-set-key (kbd "M-l") 'goto-line-with-feedback)
-(global-set-key (kbd "M-z") 'zap-up-to-char)
-(global-set-key (kbd "C-x -") 'toggle-windows-split)
-(global-set-key (kbd "<f12>") 'multi-term-dedicated-toggle)
-(global-set-key (kbd "C-c p") 'partially/visit-partial)
-(global-set-key (kbd "C-c ,,") 'ruby-open-spec-other-buffer)
-(global-set-key (kbd "<C-S-down>") 'move-line-down)
-(global-set-key (kbd "<C-S-up>") 'move-line-up)
+(global-set-key (kbd "C-c s") 'shell)
+(global-set-key (kbd "C-x C-v") 'ido-find-file-other-window)
+(global-set-key (kbd "C-c c") 'switch-to-previous-buffer)
+(global-set-key (kbd "M-t") 'textmate-goto-file)
+(global-set-key (kbd "M-T") 'textmate-goto-symbol)
+(global-set-key (kbd "C-c d") 'duplicate-line)
+(global-set-key (kbd "M-]") 'textmate-shift-right)
+(global-set-key (kbd "M-[") 'textmate-shift-left)
+(global-set-key (kbd "M-/") 'comment-or-uncomment-region)
+(global-set-key (kbd "C-x à") 'delete-window)
+(global-set-key (kbd "C-x &") 'delete-other-windows)
+(global-set-key (kbd "C-x é") 'split-window-below)
+(global-set-key (kbd "C-x \"") 'split-window-right)
+(global-set-key (kbd "M-L") 'textmate-select-line)
+(global-set-key (kbd "C-c o") 'vi-open-line-above)
+(global-set-key (kbd "C-o") 'vi-open-line-below)
+(global-set-key (kbd "C-c g") 'magit-status)
+(global-set-key (kbd "M-l") 'goto-line-with-feedback)
+(global-set-key (kbd "M-z") 'zap-up-to-char)
+(global-set-key (kbd "C-x -") 'toggle-windows-split)
+(global-set-key (kbd "<f12>") 'multi-term-dedicated-toggle)
+(global-set-key (kbd "C-c p") 'partially/visit-partial)
+(global-set-key (kbd "C-c ,,") 'ruby-open-spec-other-buffer)
+(global-set-key (kbd "<C-S-down>") 'move-line-down)
+(global-set-key (kbd "<C-S-up>") 'move-line-up)
+(global-set-key (kbd "<C-return>") 'open-line-below)
+(global-set-key (kbd "<C-S-return>") 'open-line-above)

0 comments on commit 4d1ae01

Please sign in to comment.