.emacs.d/ag-functions.el
author Adam Gomaa <adam@gomaa.us>
Sun Dec 18 13:13:02 2011 -0500
changeset 521 67f37d330ad0
parent 322 b0123230dc77
permissions -rw-r--r--
Remove project & _list_projects, I don't use them anymore.
     1 
     2 (defun kill-whole-line ()
     3   (interactive)
     4   (move-beginning-of-line 1)
     5   (kill-line 1)
     6   )
     7 
     8 (defun jao-toggle-selective-display (column)
     9   (interactive "P")
    10   (set-selective-display
    11    (if selective-display nil (or column 1))))
    12 
    13 
    14 
    15 (defun diff-buffer-with-associated-file ()
    16   "View the differences between BUFFER and its associated file.
    17 This requires the external program \"diff\" to be in your `exec-path'. 
    18 Returns nil if no differences found, 't otherwise."
    19   (interactive)
    20   (let ((buf-filename buffer-file-name)
    21         (buffer (current-buffer)))
    22     (unless buf-filename
    23       (error "Buffer %s has no associated file" buffer))
    24     (let ((diff-buf (get-buffer-create
    25                      (concat "*Assoc file diff: "
    26                              (buffer-name)
    27                              "*"))))
    28       (with-current-buffer diff-buf
    29         (setq buffer-read-only nil)
    30         (erase-buffer))
    31       (let ((tempfile (make-temp-file "buffer-to-file-diff-")))
    32         (unwind-protect
    33             (progn
    34               (with-current-buffer buffer
    35                 (write-region (point-min) (point-max) tempfile nil 'nomessage))
    36               (if (zerop
    37                    (apply #'call-process "diff" nil diff-buf nil
    38                           (append
    39                            (when (and (boundp 'ediff-custom-diff-options)
    40                                       (stringp ediff-custom-diff-options))
    41                              (list ediff-custom-diff-options))
    42                            (list buf-filename tempfile))))
    43                   (progn
    44                     (message "No differences found")
    45                     nil)
    46                 (progn
    47                   (with-current-buffer diff-buf
    48                     (goto-char (point-min))
    49                     (if (fboundp 'diff-mode)
    50                         (diff-mode)
    51                       (fundamental-mode)))
    52                   (display-buffer diff-buf)
    53                   t)))
    54           (when (file-exists-p tempfile)
    55             (delete-file tempfile)))))))
    56 
    57 ;; tidy up diffs when closing the file
    58 (defun kill-associated-diff-buf ()
    59   (let ((buf (get-buffer (concat "*Assoc file diff: "
    60                              (buffer-name)
    61                              "*"))))
    62     (when (bufferp buf)
    63       (kill-buffer buf))))
    64 
    65 (add-hook 'kill-buffer-hook 'kill-associated-diff-buf)
    66 
    67 (defun de-context-kill (arg)
    68   "Kill buffer, taking gnuclient into account."
    69   (interactive "p")
    70   (when (and (buffer-modified-p)
    71              buffer-file-name
    72              (not (string-match "\\*.*\\*" (buffer-name)))
    73              ;; erc buffers will be automatically saved
    74              (not (eq major-mode 'erc-mode))
    75              (= 1 arg))
    76     (let ((differences 't))
    77     (when (file-exists-p buffer-file-name)
    78       (setq differences (diff-buffer-with-associated-file)))
    79     (error (if differences 
    80                "Buffer has unsaved changes"
    81              "Buffer has unsaved changes, but no differences wrt. the file"))))
    82   (if (and (boundp 'gnuserv-minor-mode)
    83              gnuserv-minor-mode)
    84       (gnuserv-edit)
    85     (set-buffer-modified-p nil)
    86     (kill-buffer (current-buffer))))
    87 
    88 
    89 (fset 'lparen
    90       (lambda (&optional arg) "Keyboard macro." (interactive "p") (kmacro-exec-ring-item (quote ("\\left(" 0 "%d")) arg)))
    91 (fset 'rparen
    92       (lambda (&optional arg) "Keyboard macro." (interactive "p") (kmacro-exec-ring-item (quote ("\\right)" 0 "%d")) arg)))
    93 
    94 (defun my-list-buffers (&optional files-only)
    95   "Opens list-buffers and put focus on it"
    96   (interactive "P")
    97   (let ((b (list-buffers-noselect files-only)))
    98     (display-buffer b)
    99     (pop-to-buffer b)
   100     (delete-other-windows)))
   101 
   102 
   103 (defun jao-toggle-selective-display (column)
   104   (interactive "P")
   105   (set-selective-display
   106    (if selective-display nil (or column 1))))
   107 
   108 (defun really-revert-buffer ()
   109   "Revert the buffer without asking for confirmation."
   110   (interactive)
   111   (revert-buffer t t t))
   112 
   113 (defun close-project (project)
   114   "Filesets never seems to work."
   115   (interactive "P")
   116   (dolist (buffer (buffer-list))
   117     (with-current-buffer buffer
   118       (if (and (buffer-file-name)
   119                (string-match project (buffer-file-name)))
   120           (kill-buffer buffer)))))
   121 
   122 (defun my-clean-line (foo)
   123   (interactive "P")
   124   (indent-for-tab-command)
   125   (move-end-of-line nil)
   126   (delete-horizontal-space)
   127   (next-logical-line))
   128 
   129 (defun insert-time-stamp ()
   130   (interactive)
   131   (insert-and-inherit (time-stamp-yyyy/mm/dd) " - "(time-stamp-hh:mm:ss))
   132   (newline))
   133 
   134 (provide 'ag-functions)