summary refs log tree commit diff stats
path: root/emacs/elisp/ap-functions.el
blob: 4c3000150eed3bfe4d9cd3b70f98553564b8ad3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
;;;###autoload
(defun ap/remove-extra-cr ()
  "Remove extraneous CR codes from a file"
  (interactive)
  (save-excursion
    (goto-char (point-min))
    (while (search-forward "
" nil t)
      (replace-match ""))))

;;;###autoload
(defun copy-rectangle (start end)
  "Copy the region-rectangle."
  (interactive "r")
  (setq killed-rectangle (extract-rectangle start end)))

;;;###autoload
(defun eval-and-replace ()
  "Replace the preceding sexp with its value."
  (interactive)
  (backward-kill-sexp)
  (condition-case nil
      (prin1 (eval (read (current-kill 0)))
             (current-buffer))
    (error (message "Invalid expression")
           (insert (current-kill 0)))))

;;;###autoload
(defun ap/byte-compile-get-dest (filename)
  (let ((basename (file-name-nondirectory filename))
        (dirname  (file-name-directory    filename)))
    (cond
     ((string-equal basename "init.el")
      (if (file-exists-p (concat user-emacs-directory "init.el"))
          (concat user-emacs-directory "init.elc")))
     (t (let (byte-compile-dest-file-function)
          (byte-compile-dest-file filename))))))

;;;###autoload
(defun shell-execute (to-current-buffer)
  (interactive "P")
  (let ((file-buffer (if (buffer-file-name)
                         (file-name-nondirectory (buffer-file-name))
                       ""))
        (command (read-shell-command "Shell command: " nil nil nil)))
    (shell-command (replace-regexp-in-string "%" file-buffer command) to-current-buffer)))

(provide 'ap-functions)