Personal emacs config
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.3 KiB

  1. ;;; pacfiles-utils.el --- common utilities of pacfiles-mode -*- lexical-binding: t; -*-
  2. ;;; Commentary:
  3. ;; Utility functions used throughout pacfiles-mode
  4. ;;
  5. ;;; Code:
  6. (defun pacfiles--calculate-merge-file (file path)
  7. "File name associated to the merge file tied to FILE located in PATH."
  8. (concat path (substring (secure-hash 'md5 file) 0 10) ".pacmerge"))
  9. (defun pacfiles--add-sudo-maybe (file-path permission)
  10. "Add \"/sudo::\" to FILE-PATH if the file does not meet the PERMISSION.
  11. FILE-PATH is a variable pointing to a file name.
  12. PERMISSION is either \":read\" or \":write\""
  13. (let ((predicate (cond ((eq permission :read) #'file-readable-p)
  14. ((eq permission :write) #'file-writable-p)
  15. (t (user-error "Unknown keyword"))))
  16. (apt-path file-path))
  17. (unless (funcall predicate apt-path)
  18. (setq apt-path (concat "/sudo::" apt-path))
  19. (unless (funcall predicate apt-path)
  20. (error "Could not %s \"%s\"" (if (eq permission :read) "read" "write") file-path)))
  21. apt-path))
  22. (defun pacfiles--var-to-cons (var)
  23. "Create a cons of the VAR symbol and the VAR value."
  24. `(,var . ,(symbol-value var)))
  25. (defun pacfiles--cons-to-var (cons)
  26. "Set the `car' of CONS to the `cdr' of CONS."
  27. (let ((var (car cons)))
  28. (set var (cdr cons))))
  29. (provide 'pacfiles-utils)
  30. ;;; pacfiles-utils.el ends here