Another copy of my dotfiles. Because I don't completely trust GitHub.
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.

89 lines
2.7 KiB

4 years ago
  1. # Copyright 2015 by David A. Golden. All rights reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  4. # not use this file except in compliance with the License. You may obtain
  5. # a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
  6. #
  7. # ABOUT
  8. #
  9. # atcomplete.pl
  10. #
  11. # Adds nick completion when prefixed with '@' for use with IRC gateways
  12. # for Slack, Flowdock, etc. as these require the '@' to highlight users
  13. #
  14. # CONFIG
  15. #
  16. # /set plugins.var.perl.atcomplete.enabled
  17. #
  18. # HISTORY
  19. #
  20. # 0.001 -- xdg, 2016-04-06
  21. #
  22. # - initial release
  23. #
  24. # REPOSITORY
  25. #
  26. # https://github.com/xdg/weechat-atcomplete
  27. use strict;
  28. use warnings;
  29. my $SCRIPT_NAME = "atcomplete";
  30. my $VERSION = "0.001";
  31. my %options_default = (
  32. 'enabled' => ['on', 'enable completion of nicks starting with @'],
  33. );
  34. my %options = ();
  35. weechat::register($SCRIPT_NAME, "David A. Golden", $VERSION,
  36. "Apache2", "atcomplete - do nick completion following @", "", "");
  37. init_config();
  38. weechat::hook_config("plugins.var.perl.$SCRIPT_NAME.*", "toggle_config_by_set", "");
  39. weechat::hook_completion("nicks", "Add @ prefix to nick completion", "complete_at_nicks", "");
  40. sub complete_at_nicks {
  41. my ($data, $completion_item, $buffer, $completion ) = @_;
  42. return weechat::WEECHAT_RC_OK() unless $options{enabled} eq 'on';
  43. my $nicklist = weechat::infolist_get("nicklist", weechat::current_buffer(), "");
  44. if ($nicklist ne "") {
  45. while (weechat::infolist_next($nicklist)) {
  46. next unless weechat::infolist_string($nicklist, "type") eq "nick";
  47. my $nick = weechat::infolist_string($nicklist, "name");
  48. weechat::hook_completion_list_add($completion, "\@$nick", 1, weechat::WEECHAT_LIST_POS_SORT());
  49. }
  50. }
  51. weechat::infolist_free($nicklist);
  52. return weechat::WEECHAT_RC_OK();
  53. }
  54. sub toggle_config_by_set {
  55. my ($pointer, $name, $value) = @_;
  56. $name = substr($name, length("plugins.var.perl.".$SCRIPT_NAME."."), length($name));
  57. $options{$name} = $value;
  58. return weechat::WEECHAT_RC_OK();
  59. }
  60. sub init_config {
  61. my $version = weechat::info_get("version_number", "") || 0;
  62. foreach my $option (keys %options_default)
  63. {
  64. if (!weechat::config_is_set_plugin($option))
  65. {
  66. weechat::config_set_plugin($option, $options_default{$option}[0]);
  67. $options{$option} = $options_default{$option}[0];
  68. }
  69. else
  70. {
  71. $options{$option} = weechat::config_get_plugin($option);
  72. }
  73. if ($version >= 0x00030500)
  74. {
  75. weechat::config_set_desc_plugin($option, $options_default{$option}[1]." (default: \"".$options_default{$option}[0]."\")");
  76. }
  77. }
  78. }